:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --line: #cfd9e6;
  --line-strong: #9fb0c4;
  --text: #172033;
  --muted: #637083;
  --subtle: #8795a8;
  --accent: #1f66e5;
  --accent-strong: #0f4ec2;
  --accent-soft: #e8f0ff;
  --danger: #ef4444;
  --danger-soft: #fff1f1;
  --expert: #1d7a58;
  --research: #8a5a10;
  --shadow: 0 16px 40px rgba(23, 32, 51, 0.12);
  --radius: 8px;
  --header-h: 58px;
  font-family: "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.app-header {
  min-height: var(--header-h);
  display: grid;
  grid-template-columns: max-content 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.title-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  flex: 0 0 auto;
}

.title-block h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
  white-space: nowrap;
}

.panel-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.template-tabs {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: thin;
}

.template-tab {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius);
  white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease, color 0.16s ease;
}

.template-tab:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

.template-tab:active,
.button:active,
.format-toolbar button:active,
.seal-role-switch button:active {
  transform: translateY(1px);
}

.template-tab.is-active {
  background: var(--accent-soft);
  border-color: #9bbcff;
  color: var(--accent-strong);
  font-weight: 700;
}

.template-tab[data-mode="expert"] {
  border-color: rgba(29, 122, 88, 0.35);
  color: var(--expert);
}

.template-tab[data-mode="research"] {
  border-color: rgba(138, 90, 16, 0.35);
  color: var(--research);
}

.header-actions,
.bottom-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 15px;
  color: var(--text);
  background: var(--surface);
  white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.button:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.button-primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 700;
}

.button-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.button-danger-outline {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--surface);
  font-weight: 700;
}

.button-danger-outline.is-active {
  color: #ffffff;
  background: var(--danger);
}

body.template-action-open {
  overflow: hidden;
}

.template-action-modal[hidden] {
  display: none !important;
}

.template-action-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}

.template-action-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.46);
}

.template-action-dialog {
  position: relative;
  z-index: 1;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}

.template-action-head {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 18px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
}

.template-action-head h2,
.template-action-head p,
.template-action-foot p,
.template-action-result h3,
.template-action-result p {
  margin: 0;
}

.template-action-head h2 {
  font-size: 18px;
  line-height: 1.3;
}

.template-action-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.template-action-close-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.template-action-close-icon:hover {
  border-color: var(--line-strong);
  color: var(--text);
  background: var(--surface-2);
}

.template-action-body {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 14px;
  overflow: auto;
  padding: 16px;
}

.template-action-field {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.template-action-field > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.template-action-field textarea {
  width: 100%;
  min-height: 126px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  color: var(--text);
  background: var(--surface);
  font-size: 14px;
  line-height: 1.65;
}

.template-action-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 102, 229, 0.12);
}

.template-action-result {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.template-action-result h3 {
  font-size: 15px;
}

.template-action-result p,
.template-action-result li {
  color: #465670;
  font-size: 13px;
  line-height: 1.7;
}

.template-action-result ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 18px;
}

.template-action-options {
  display: grid;
  gap: 8px;
  margin-top: 2px;
}

.template-action-option {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.template-action-option > div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.template-action-option strong,
.template-action-option span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-action-option strong {
  font-size: 13px;
}

.template-action-option span,
.template-action-empty {
  color: var(--muted);
  font-size: 12px;
}

.template-empty-state {
  min-height: 360px;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
}

.template-empty-state h2 {
  margin: 0;
  color: var(--text);
}

.template-empty-state p {
  margin: 0;
}

.template-action-foot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 13px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.template-action-foot p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.template-action-foot > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button-ghost {
  background: var(--surface);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns:
    minmax(420px, 1fr)
    12px
    minmax(240px, var(--variables-pane-width, 300px))
    12px
    minmax(300px, var(--ai-pane-width, 360px));
  gap: 0;
  padding: 12px 14px;
  overflow: hidden;
}

.workspace.is-ai-hidden {
  grid-template-columns:
    minmax(420px, 1fr)
    12px
    minmax(240px, var(--variables-pane-width, 340px));
}

.workspace.is-ai-hidden [data-panel-resizer="variables-ai"] {
  display: none;
}

.panel-resizer {
  position: relative;
  min-width: 12px;
  align-self: stretch;
  cursor: col-resize;
  touch-action: none;
  outline: none;
  z-index: 5;
}

.panel-resizer::before {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 50%;
  width: 2px;
  border-radius: 2px;
  background: #aebdce;
  transform: translateX(-50%);
  transition: width 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.panel-resizer:hover::before,
.panel-resizer:focus-visible::before,
.panel-resizer.is-dragging::before {
  width: 4px;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 102, 229, 0.12);
}

body.is-panel-resizing,
body.is-panel-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.editor-panel,
.side-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(23, 32, 51, 0.03);
}

.editor-panel {
  display: grid;
  grid-template-rows: auto 1fr;
}

.editor-panel.is-editor-chrome-hidden:not(.is-seal-mode) {
  grid-template-rows: 1fr;
}

.editor-panel.is-editor-chrome-hidden > .panel-head {
  display: none;
}

.editor-panel.is-seal-mode > .panel-head {
  display: none;
}

.panel-head {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.panel-head.compact {
  min-height: 46px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.25;
  letter-spacing: 0;
}

.format-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.format-toolbar button {
  min-width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #53647a;
  background: #f6f9fd;
  padding: 0 7px;
}

.format-toolbar button:hover {
  color: var(--accent-strong);
  border-color: #b7c9e3;
}

.seal-dock {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff8f8;
}

.seal-dock[hidden] {
  display: none;
}

.seal-dock-title strong {
  display: block;
  font-size: 13px;
}

.seal-dock-title {
  grid-column: 1;
  grid-row: 1;
}

.seal-dock-title span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.seal-role-switch {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
}

.seal-role-switch button {
  flex: 0 1 auto;
  width: fit-content;
  min-width: 52px;
  max-width: 100%;
  height: 32px;
  border: 1px solid #f4b5b5;
  border-radius: 6px;
  background: #ffffff;
  color: #a92323;
  padding: 0 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: grab;
}

.seal-role-switch button:active {
  cursor: grabbing;
}

.seal-role-switch button.is-active {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

.seal-dock-actions {
  grid-column: 3;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

#detectSignersButton,
#saveSealButton {
  flex: 0 0 auto;
}

.document-stage {
  min-height: 0;
  overflow: auto;
  padding: 14px;
  background:
    linear-gradient(90deg, rgba(31, 102, 229, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(31, 102, 229, 0.04) 1px, transparent 1px),
    #edf3f9;
  background-size: 22px 22px;
}

.document-page {
  width: min(100%, 905px);
  min-height: 452px;
  margin: 0 auto;
  position: relative;
  background: #ffffff;
  border: 1px solid #cbd7e7;
  border-radius: var(--radius);
  padding: 48px 34px 32px;
  box-shadow: var(--shadow);
  outline: none;
  color: #1d2636;
  line-height: 1.72;
  font-size: 14px;
}

.document-page.seal-mode {
  cursor: crosshair;
}

.document-page.seal-drop-target {
  outline: 3px solid rgba(239, 68, 68, 0.48);
  outline-offset: -4px;
  background: #fffdfd;
}

.pdf-page-overlay.seal-drop-target {
  outline: 3px solid rgba(239, 68, 68, 0.58);
  outline-offset: -4px;
  background: rgba(255, 241, 241, 0.2);
}

.document-page h2 {
  margin: 0 0 22px;
  text-align: center;
  font-size: 24px;
  letter-spacing: 0;
}

.document-page p {
  margin: 14px 0;
}

.ai-generated-requirement {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 10px;
  margin: -8px 0 18px;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: #2b405f;
  font-size: 12px;
  line-height: 1.55;
}

.ai-generated-requirement strong {
  color: var(--accent-strong);
}

.document-page.is-custom-file-preview[data-custom-preview="pdf"] {
  min-height: 720px;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.custom-file-preview-head {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.document-page[data-custom-preview="pdf"] .custom-file-preview-head {
  position: sticky;
  top: 0;
  z-index: 12;
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 4px 14px rgba(23, 32, 51, 0.08);
  backdrop-filter: blur(8px);
}

.custom-file-preview-head strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-file-preview-head span {
  flex: 0 0 auto;
}

.custom-pdf-pages {
  display: grid;
  justify-items: center;
  gap: 18px;
  width: 100%;
  min-height: 620px;
}

.custom-pdf-loading,
.custom-pdf-error {
  width: 100%;
  min-height: 360px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
}

.custom-pdf-error strong {
  color: #b42318;
}

.custom-pdf-error span {
  max-width: 520px;
  text-align: center;
  overflow-wrap: anywhere;
}

.pdf-page-sheet {
  position: relative;
  width: min(100%, 900px);
  overflow: hidden;
  border: 1px solid #b8c5d6;
  border-radius: 2px;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(23, 32, 51, 0.14);
}

.pdf-page-sheet::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  width: 24px;
  height: 24px;
  margin: -12px;
  border: 2px solid #d5deea;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: pdf-page-loading 0.8s linear infinite;
}

.pdf-page-sheet[data-render-state="ready"]::before,
.pdf-page-sheet[data-render-state="failed"]::before {
  display: none;
}

.pdf-page-sheet[data-render-state="failed"]::after {
  content: attr(data-render-error);
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  padding: 24px;
  color: #b42318;
  text-align: center;
  background: #fff8f8;
}

.pdf-page-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #ffffff;
}

.pdf-page-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  touch-action: none;
}

.document-page.seal-mode .pdf-page-overlay {
  pointer-events: auto;
  cursor: crosshair;
}

.pdf-page-label {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 6;
  min-width: 42px;
  padding: 3px 6px;
  border: 1px solid rgba(159, 176, 196, 0.7);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.88);
  color: #53647a;
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
  pointer-events: none;
}

@keyframes pdf-page-loading {
  to {
    transform: rotate(360deg);
  }
}

.custom-template-text {
  min-height: 360px;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: inherit;
  font: inherit;
  line-height: inherit;
}

.custom-template-file-summary {
  min-height: 350px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

.custom-template-file-summary strong {
  max-width: min(100%, 560px);
  overflow-wrap: anywhere;
  font-size: 18px;
}

.custom-template-file-summary > span:last-child {
  color: var(--muted);
  font-size: 13px;
}

.custom-template-file-type {
  display: grid;
  place-items: center;
  width: 58px;
  height: 68px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.template-table,
.uploaded-docx-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 16px;
  table-layout: fixed;
}

.template-table td,
.uploaded-docx-table td {
  border: 1px solid #111827;
  padding: 4px 8px;
  line-height: 1.35;
  vertical-align: middle;
  word-break: break-word;
}

.template-table td:nth-child(odd),
.uploaded-docx-table td:nth-child(odd) {
  width: 24%;
  color: #344257;
}

.signature-row,
.uploaded-contract-signature-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-top: 30px;
}

.signature-row-applicant,
.uploaded-contract-signature-block.uploaded-contract-signature-applicant {
  grid-template-columns: minmax(180px, 42%);
  justify-content: end;
}

.signature-slot-applicant,
.uploaded-contract-signature-applicant .uploaded-contract-signature-party {
  text-align: left;
}

.signature-slot,
.uploaded-contract-signature-party {
  min-height: 64px;
  padding-top: 4px;
  border-top: 1px solid transparent;
}

.signature-slot strong,
.uploaded-contract-signature-party strong {
  font-weight: 600;
}

.document-page.seal-mode .signature-slot,
.document-page.seal-mode .uploaded-contract-signature-party {
  border-top-color: rgba(239, 68, 68, 0.28);
  background: rgba(255, 241, 241, 0.62);
}

.seal-marker {
  position: absolute;
  z-index: 5;
  border: 2px dashed var(--danger);
  border-radius: 6px;
  background: rgba(255, 241, 241, 0.88);
  color: #991b1b;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  transform: translate(-50%, -50%);
  user-select: none;
  touch-action: none;
  padding: 6px 18px 6px 10px;
}

.seal-marker-label {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seal-resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 16px;
  height: 16px;
  border: 1px solid var(--danger);
  border-radius: 4px;
  background: #ffffff;
  cursor: nwse-resize;
  padding: 0;
  touch-action: none;
}

.seal-resize-handle::before {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--danger);
  border-bottom: 2px solid var(--danger);
}

.seal-marker.is-active {
  background: var(--danger);
  color: #ffffff;
  box-shadow: 0 10px 20px rgba(239, 68, 68, 0.22);
}

.seal-marker.is-company-seal {
  height: auto;
  min-height: 0;
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: transparent;
  color: var(--danger);
}

.seal-marker.is-company-seal.is-active {
  background: transparent;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2), 0 10px 20px rgba(239, 68, 68, 0.16);
}

.company-seal-visual {
  position: absolute;
  inset: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 3px double #dc2626;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #dc2626;
  line-height: 1;
  text-align: center;
  transform: rotate(-5deg);
}

.company-seal-visual::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(220, 38, 38, 0.72);
  border-radius: 50%;
  pointer-events: none;
}

.company-seal-star {
  position: relative;
  z-index: 1;
  font-size: 24px;
  line-height: 0.9;
}

.company-seal-company,
.company-seal-caption {
  position: relative;
  z-index: 1;
  max-width: 72%;
  overflow: hidden;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.company-seal-caption {
  font-size: 8px;
  font-weight: 600;
}

.cross-page-boundary {
  position: absolute;
  left: 16px;
  right: 16px;
  z-index: 3;
  border-top: 1px dashed #c4cfdd;
  pointer-events: none;
}

.cross-page-seal {
  position: absolute;
  right: 8px;
  z-index: 7;
  width: 74px;
  aspect-ratio: 1 / 1;
  transform: translateY(-50%);
  user-select: none;
}

.cross-page-seal .company-seal-visual {
  inset: 0;
}

.company-seal-visual.is-compact {
  gap: 1px;
  border-width: 2px;
}

.company-seal-visual.is-compact::after {
  inset: 5px;
}

.company-seal-visual.is-compact .company-seal-star {
  font-size: 17px;
}

.company-seal-visual.is-compact .company-seal-company {
  max-width: 68%;
  font-size: 7px;
}

.company-seal-visual.is-compact .company-seal-caption {
  font-size: 7px;
}

.cross-page-seal-remove {
  position: absolute;
  top: -7px;
  right: -7px;
  z-index: 2;
  width: 22px;
  height: 22px;
  border: 1px solid #ef4444;
  border-radius: 50%;
  background: #ffffff;
  color: #dc2626;
  padding: 0;
  font-size: 17px;
  line-height: 18px;
  box-shadow: 0 4px 10px rgba(23, 32, 51, 0.16);
}

.cross-page-seal-remove:hover,
.cross-page-seal-remove:focus-visible {
  background: var(--danger);
  color: #ffffff;
  outline: none;
}

.side-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.variable-list {
  min-height: 0;
  overflow: auto;
  padding: 10px 14px 14px;
}

.variable-field {
  display: grid;
  gap: 6px;
  margin-bottom: 9px;
}

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

.variable-field input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbff;
  color: var(--text);
  padding: 0 11px;
  font-weight: 700;
}

.variable-field input:focus,
.chat-input-row textarea:focus {
  outline: 2px solid rgba(31, 102, 229, 0.16);
  border-color: #8db0ef;
  background: #ffffff;
}

.ai-panel {
  grid-template-rows: auto auto auto 1fr auto;
}

.ai-panel[hidden],
#aiMascotButton[hidden] {
  display: none;
}

.ai-mascot-button {
  position: fixed;
  right: 16px;
  bottom: 72px;
  z-index: 45;
  width: 96px;
  height: 96px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  filter: drop-shadow(0 8px 10px rgba(23, 32, 51, 0.22));
  transition: transform 0.18s ease, filter 0.18s ease;
}

.ai-mascot-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.ai-mascot-button::after {
  content: attr(data-tooltip);
  position: absolute;
  top: 8px;
  right: 82px;
  width: max-content;
  max-width: 120px;
  padding: 6px 9px;
  border-radius: 6px;
  background: #172033;
  color: #ffffff;
  font-size: 12px;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  transform: translateX(6px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.ai-mascot-button:hover {
  transform: translateY(-4px) scale(1.03);
  filter: drop-shadow(0 12px 14px rgba(23, 32, 51, 0.26));
}

.ai-mascot-button:hover::after,
.ai-mascot-button:focus-visible::after {
  opacity: 1;
  transform: translateX(0);
}

.ai-mascot-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 50%;
}

.panel-toggle-button {
  min-width: 52px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  padding: 0 10px;
  white-space: nowrap;
}

.panel-toggle-button:hover {
  color: var(--accent-strong);
  border-color: #a9bfdf;
  background: var(--accent-soft);
}

.learning-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.learning-item {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 8px;
}

.learning-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.learning-item strong {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-prompts {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.quick-prompts button {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: #41516a;
  padding: 0 11px;
  white-space: nowrap;
}

.quick-prompts button:hover {
  color: var(--accent-strong);
  border-color: #a9bfdf;
}

.chat-log {
  min-height: 0;
  overflow: auto;
  padding: 14px;
  background: #f6f9fd;
}

.chat-message {
  max-width: 94%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #ffffff;
  color: #263247;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 13px;
}

.chat-message.user {
  margin-left: auto;
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.chat-message.assistant {
  margin-right: auto;
}

.chat-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.chat-input-row textarea {
  resize: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  min-height: 42px;
  color: var(--text);
}

.bottom-actions {
  justify-content: flex-end;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
}

.footer-spacer {
  flex: 1 1 auto;
  min-width: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 74px;
  z-index: 50;
  min-width: 220px;
  max-width: 360px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: #172033;
  color: #ffffff;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  box-shadow: var(--shadow);
  font-size: 13px;
  transition: right 0.18s ease, opacity 0.18s ease, transform 0.18s ease;
}

body.is-ai-hidden .toast {
  right: 120px;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.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;
}

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

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .app-header {
    grid-template-columns: 1fr;
    align-items: stretch;
    position: static;
  }

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

  .header-actions {
    justify-content: flex-end;
  }

  .workspace,
  .workspace.is-ai-hidden {
    grid-template-columns: 1fr;
    gap: 12px;
    overflow: visible;
  }

  .panel-resizer {
    display: none;
  }

  .variables-panel {
    min-height: 440px;
  }

  .ai-panel {
    min-height: 520px;
  }
}

@media (max-width: 760px) {
  .template-action-modal {
    align-items: end;
    padding: 0;
  }

  .template-action-dialog {
    width: 100%;
    max-height: 92dvh;
    border-radius: 8px 8px 0 0;
  }

  .template-action-head,
  .template-action-foot {
    grid-template-columns: 1fr;
  }

  .template-action-close-icon {
    position: absolute;
    top: 12px;
    right: 12px;
  }

  .template-action-head > div {
    padding-right: 42px;
  }

  .template-action-foot > div {
    justify-content: flex-end;
  }

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

  .ai-generated-requirement {
    grid-template-columns: 1fr;
  }

  .workspace {
    padding: 8px;
  }

  .seal-dock {
    grid-template-columns: minmax(0, 1fr) max-content;
  }

  .seal-dock-title {
    grid-column: 1;
    grid-row: 1;
  }

  .seal-role-switch {
    grid-column: 1 / -1;
    grid-row: 2;
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(72px, 1fr);
  }

  .seal-role-switch button {
    width: 100%;
    min-width: 0;
  }

  #saveSealButton {
    grid-column: 2;
    grid-row: 1;
  }

  .document-stage {
    padding: 8px;
  }

  .document-page {
    padding: 34px 16px 28px;
    font-size: 13px;
  }

  .document-page.is-custom-file-preview[data-custom-preview="pdf"] {
    min-height: 560px;
    padding: 0;
  }

  .custom-pdf-pages {
    gap: 10px;
  }

  .cross-page-seal {
    right: 4px;
    width: 64px;
  }

  .signature-row,
  .uploaded-contract-signature-block,
  .learning-strip,
  .chat-input-row {
    grid-template-columns: 1fr;
  }

  .bottom-actions {
    overflow-x: auto;
    justify-content: flex-start;
  }

  .footer-spacer {
    display: none;
  }

  .ai-mascot-button {
    right: 8px;
    bottom: 68px;
    width: 80px;
    height: 80px;
  }

  .ai-mascot-button::after {
    right: 70px;
  }

  body.is-ai-hidden .toast {
    right: 96px;
  }

}

@media (prefers-reduced-motion: reduce) {
  .pdf-page-sheet::before,
  .ai-mascot-button,
  .ai-mascot-button::after {
    transition: none;
  }
}
