:root {
  --pdf-bg: #060b16;
  --pdf-bg-elevated: #101b31;
  --pdf-panel: #0d1527;
  --pdf-panel-soft: rgba(255, 255, 255, 0.035);
  --pdf-text: #e5eefc;
  --pdf-text-soft: #c2d0e7;
  --pdf-muted: #8fa2bf;
  --pdf-line: rgba(148, 163, 184, 0.16);
  --pdf-line-strong: rgba(148, 163, 184, 0.28);
  --pdf-accent: #38bdf8;
  --pdf-accent-strong: #22d3ee;
  --pdf-accent-soft: rgba(56, 189, 248, 0.14);
  --pdf-teal: #34d399;
  --pdf-teal-soft: rgba(52, 211, 153, 0.14);
  --pdf-danger: #ef4444;
  --pdf-danger-soft: rgba(239, 68, 68, 0.14);
  --pdf-warning: #f59e0b;
  --pdf-shadow: 0 20px 54px rgba(2, 6, 23, 0.28);
  --pdf-shadow-soft: 0 16px 42px rgba(2, 6, 23, 0.24);
  --pdf-radius: 8px;
  --pdf-toolbar-height: 64px;
  --pdf-status-height: 44px;
  color-scheme: dark;
}

[data-theme="light"] {
  --pdf-bg: #f5f7fb;
  --pdf-bg-elevated: #ffffff;
  --pdf-panel: #ffffff;
  --pdf-panel-soft: #f8fafc;
  --pdf-text: #172033;
  --pdf-text-soft: #526070;
  --pdf-muted: #7a8797;
  --pdf-line: #d8e0ea;
  --pdf-line-strong: #bac7d6;
  --pdf-accent: #2563eb;
  --pdf-accent-strong: #1d4ed8;
  --pdf-accent-soft: rgba(37, 99, 235, 0.11);
  --pdf-teal: #0f9f8f;
  --pdf-teal-soft: rgba(15, 159, 143, 0.13);
  --pdf-danger: #dc2626;
  --pdf-danger-soft: rgba(220, 38, 38, 0.1);
  --pdf-warning: #b7791f;
  --pdf-shadow: 0 18px 44px rgba(31, 41, 55, 0.14);
  --pdf-shadow-soft: 0 10px 30px rgba(31, 41, 55, 0.1);
  color-scheme: light;
}

[data-theme="dark"] {
  color-scheme: dark;
}

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

html,
body {
  min-width: 320px;
}

body {
  margin: 0;
}

body:not(.tool-page-body) {
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--pdf-text);
  background: var(--pdf-bg);
}

body.pdf-editor-standalone {
  min-height: 100vh;
}

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

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.pdf-editor-noscript {
  max-width: 680px;
  margin: 32px auto;
  padding: 24px;
  border: 1px solid var(--pdf-line);
  border-radius: var(--pdf-radius);
  background: var(--pdf-panel);
  color: var(--pdf-text);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  box-shadow: var(--pdf-shadow-soft);
}

.pdf-editor-page {
  width: 100%;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--pdf-text);
}

.pdf-editor-shell {
  display: grid;
  grid-template-rows: auto minmax(560px, 1fr) auto;
  min-height: min(920px, calc(100vh - 24px));
  background: var(--pdf-bg);
  color: var(--pdf-text);
  border: 1px solid var(--pdf-line);
  border-radius: var(--pdf-radius);
  overflow: hidden;
  box-shadow: var(--pdf-shadow);
}

body.pdf-editor-standalone .pdf-editor-shell {
  min-height: 100vh;
  border: 0;
  border-radius: 0;
}

.pdf-editor-toolbar,
.pdf-editor-statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border-color: var(--pdf-line);
  background: var(--pdf-bg-elevated);
}

.pdf-editor-toolbar {
  min-height: var(--pdf-toolbar-height);
  padding: 10px 14px;
  border-bottom: 1px solid var(--pdf-line);
}

.pdf-editor-toolbar-primary,
.pdf-editor-toolbar-group,
.pdf-editor-status-actions,
.pdf-page-actions,
.pdf-editor-tool-grid {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pdf-editor-toolbar-primary {
  min-width: 0;
  flex: 1;
  flex-wrap: wrap;
}

.pdf-editor-toolbar-group {
  padding: 4px;
  border: 1px solid var(--pdf-line);
  border-radius: var(--pdf-radius);
  background: var(--pdf-panel-soft);
}

.pdf-editor-toolbar-spacer {
  flex: 1 1 auto;
}

.pdf-icon-button,
.pdf-tool-button,
.pdf-primary-button,
.pdf-secondary-button,
.pdf-danger-button,
.pdf-ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  max-width: 100%;
  border: 1px solid var(--pdf-line);
  border-radius: var(--pdf-radius);
  color: var(--pdf-text);
  background: var(--pdf-panel);
  line-height: 1;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.pdf-icon-button,
.pdf-tool-button {
  padding: 8px 10px;
}

.pdf-icon-button svg,
.pdf-tool-button svg,
.pdf-primary-button svg,
.pdf-secondary-button svg,
.pdf-danger-button svg,
.pdf-ghost-button svg {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
}

.pdf-icon-button span,
.pdf-tool-button span,
.pdf-primary-button span,
.pdf-secondary-button span,
.pdf-danger-button span,
.pdf-ghost-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
}

.pdf-icon-button:hover,
.pdf-tool-button:hover,
.pdf-secondary-button:hover,
.pdf-ghost-button:hover {
  border-color: var(--pdf-line-strong);
  background: var(--pdf-panel-soft);
}

.pdf-icon-button:focus-visible,
.pdf-tool-button:focus-visible,
.pdf-primary-button:focus-visible,
.pdf-secondary-button:focus-visible,
.pdf-danger-button:focus-visible,
.pdf-ghost-button:focus-visible,
.pdf-editor-field input:focus-visible,
.pdf-editor-field textarea:focus-visible,
.pdf-editor-field select:focus-visible,
.pdf-color-field input:focus-visible {
  outline: 2px solid var(--pdf-accent);
  outline-offset: 2px;
}

.pdf-primary-button {
  padding: 9px 13px;
  border-color: var(--pdf-accent);
  background: var(--pdf-accent);
  color: #fff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.2);
}

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

.pdf-secondary-button {
  padding: 9px 13px;
  border-color: var(--pdf-line);
}

.pdf-danger-button {
  padding: 9px 13px;
  border-color: var(--pdf-danger);
  background: var(--pdf-danger-soft);
  color: var(--pdf-danger);
}

.pdf-ghost-button {
  padding: 9px 11px;
  border-color: transparent;
  background: transparent;
}

.pdf-tool-button.is-active,
.pdf-icon-button.is-active {
  border-color: var(--pdf-accent);
  background: var(--pdf-accent-soft);
  color: var(--pdf-accent-strong);
}

.pdf-mobile-only {
  display: none;
}

.pdf-editor-body {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr) 304px;
  min-height: 0;
  background: var(--pdf-bg);
}

.pdf-editor-sidebar,
.pdf-editor-properties {
  min-width: 0;
  min-height: 0;
  background: var(--pdf-panel);
}

.pdf-editor-sidebar {
  border-right: 1px solid var(--pdf-line);
}

.pdf-editor-properties {
  border-left: 1px solid var(--pdf-line);
}

.pdf-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  padding: 12px;
  border-bottom: 1px solid var(--pdf-line);
}

.pdf-panel-header h2,
.pdf-properties-section h3 {
  margin: 0;
  color: var(--pdf-text);
  font-size: 14px;
  line-height: 1.2;
}

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

.pdf-thumb-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - var(--pdf-toolbar-height) - var(--pdf-status-height) - 52px);
  overflow: auto;
  padding: 12px;
}

.pdf-thumb {
  position: relative;
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--pdf-line);
  border-radius: var(--pdf-radius);
  background: var(--pdf-panel-soft);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

[data-theme="dark"] .pdf-thumb {
  box-shadow: none;
}

.pdf-thumb[draggable="true"] {
  cursor: grab;
}

.pdf-thumb.is-current {
  border-color: var(--pdf-accent);
  box-shadow: 0 0 0 2px var(--pdf-accent-soft);
}

.pdf-thumb.is-drag-over {
  border-color: var(--pdf-teal);
  background: var(--pdf-teal-soft);
}

.pdf-thumb canvas {
  width: 100%;
  min-height: 128px;
  border: 1px solid var(--pdf-line);
  border-radius: 6px;
  background: #fff;
  object-fit: contain;
}

.pdf-thumb-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--pdf-text-soft);
  font-size: 12px;
  font-weight: 700;
}

.pdf-thumb-meta small {
  color: var(--pdf-muted);
  font-size: 11px;
  font-weight: 700;
}

.pdf-editor-stage-area {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.pdf-editor-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--pdf-line);
  background: var(--pdf-bg-elevated);
}

.pdf-editor-tool-grid {
  flex-wrap: wrap;
  min-width: 0;
}

.pdf-page-actions {
  flex-wrap: wrap;
  justify-content: end;
}

.pdf-editor-canvas-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 24px;
  background: var(--pdf-bg);
}

.pdf-drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100%;
}

.pdf-drop-zone.is-dragover::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2px dashed var(--pdf-teal);
  border-radius: var(--pdf-radius);
  background: var(--pdf-teal-soft);
  pointer-events: none;
}

.pdf-page-host {
  position: relative;
  width: max-content;
  min-width: 260px;
  min-height: 360px;
  margin: 0 auto;
  transform-origin: top center;
}

.pdf-page-surface {
  position: relative;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 18px 46px rgba(31, 41, 55, 0.22);
}

.pdf-page-surface canvas {
  display: block;
}

.pdf-konva-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  touch-action: none;
}

.pdf-empty-state {
  width: min(720px, 100%);
  padding: 28px;
  border: 1px dashed var(--pdf-line-strong);
  border-radius: var(--pdf-radius);
  background: var(--pdf-panel);
  box-shadow: var(--pdf-shadow-soft);
}

.pdf-empty-state h1 {
  margin: 0;
  color: var(--pdf-text);
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.12;
}

.pdf-empty-state p {
  margin: 12px 0 0;
  color: var(--pdf-text-soft);
  line-height: 1.6;
}

.pdf-empty-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.pdf-privacy-note {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  margin-top: 18px;
  padding: 12px;
  border-radius: var(--pdf-radius);
  background: var(--pdf-teal-soft);
  color: var(--pdf-text-soft);
  font-size: 13px;
  line-height: 1.5;
}

.pdf-privacy-note svg {
  width: 18px;
  height: 18px;
  color: var(--pdf-teal);
}

.pdf-properties-body {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - var(--pdf-toolbar-height) - var(--pdf-status-height) - 52px);
  overflow: auto;
  padding: 12px;
}

.pdf-properties-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--pdf-line);
  border-radius: var(--pdf-radius);
  background: var(--pdf-panel-soft);
}

.pdf-editor-field {
  display: grid;
  gap: 6px;
}

.pdf-editor-field label,
.pdf-color-field span,
.pdf-range-head {
  color: var(--pdf-text-soft);
  font-size: 12px;
  font-weight: 800;
}

.pdf-editor-field input,
.pdf-editor-field textarea,
.pdf-editor-field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--pdf-line);
  border-radius: var(--pdf-radius);
  background: var(--pdf-panel);
  color: var(--pdf-text);
}

.pdf-editor-field input,
.pdf-editor-field select {
  padding: 0 10px;
}

.pdf-editor-field textarea {
  min-height: 92px;
  padding: 10px;
  resize: vertical;
  line-height: 1.45;
}

.pdf-field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pdf-color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pdf-color-field {
  display: grid;
  gap: 6px;
}

.pdf-color-field input {
  width: 100%;
  height: 38px;
  padding: 4px;
  border: 1px solid var(--pdf-line);
  border-radius: var(--pdf-radius);
  background: var(--pdf-panel);
}

.pdf-range-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pdf-editor-field input[type="range"] {
  padding: 0;
}

.pdf-selected-empty {
  padding: 14px;
  border: 1px dashed var(--pdf-line-strong);
  border-radius: var(--pdf-radius);
  color: var(--pdf-text-soft);
  background: var(--pdf-panel-soft);
  line-height: 1.5;
}

.pdf-editor-statusbar {
  justify-content: space-between;
  min-height: var(--pdf-status-height);
  padding: 8px 14px;
  border-top: 1px solid var(--pdf-line);
}

.pdf-status-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--pdf-text-soft);
  font-size: 13px;
  font-weight: 700;
}

.pdf-status-main span {
  white-space: nowrap;
}

.pdf-status-message {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.pdf-status-message.is-good {
  color: var(--pdf-teal);
}

.pdf-backdrop {
  display: none;
}

.pdf-hidden {
  display: none !important;
}

.pdf-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.pdf-download-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 1180px) {
  .pdf-editor-body {
    grid-template-columns: 202px minmax(0, 1fr) 280px;
  }

  .pdf-icon-button span,
  .pdf-tool-button span {
    max-width: 86px;
  }
}

@media (max-width: 940px) {
  .pdf-mobile-only {
    display: inline-flex;
  }

  .pdf-editor-shell {
    min-height: calc(100vh - 10px);
    border-radius: 0;
  }

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

  .pdf-editor-sidebar,
  .pdf-editor-properties {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 70;
    width: min(86vw, 320px);
    max-width: 320px;
    border: 0;
    box-shadow: var(--pdf-shadow);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  .pdf-editor-sidebar {
    left: 0;
  }

  .pdf-editor-properties {
    right: 0;
    transform: translateX(105%);
  }

  .pdf-editor-shell.is-left-open .pdf-editor-sidebar,
  .pdf-editor-shell.is-right-open .pdf-editor-properties {
    transform: translateX(0);
  }

  .pdf-editor-shell.is-left-open .pdf-backdrop,
  .pdf-editor-shell.is-right-open .pdf-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(15, 23, 42, 0.48);
  }

  .pdf-panel-header,
  .pdf-properties-body,
  .pdf-thumb-list {
    max-height: none;
  }

  .pdf-editor-tools {
    align-items: flex-start;
    flex-direction: column;
  }

  .pdf-page-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .pdf-editor-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .pdf-editor-toolbar-primary,
  .pdf-editor-toolbar-group {
    width: 100%;
  }

  .pdf-editor-toolbar-group {
    overflow-x: auto;
  }

  .pdf-editor-canvas-wrap {
    padding: 14px;
  }

  .pdf-tool-button,
  .pdf-icon-button,
  .pdf-primary-button,
  .pdf-secondary-button,
  .pdf-danger-button,
  .pdf-ghost-button {
    min-height: 40px;
  }

  .pdf-editor-statusbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .pdf-status-main {
    width: 100%;
    flex-wrap: wrap;
  }

  .pdf-status-actions {
    width: 100%;
    justify-content: space-between;
  }

  .pdf-field-grid,
  .pdf-color-grid {
    grid-template-columns: 1fr;
  }
}
