:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  --page-bg: #f3f6f9;
  --panel-bg: #ffffff;
  --control-bg: #f6f8fa;
  --text: #1f2328;
  --muted: #59636e;
  --border: #c8d1dc;
  --accent: #0969da;
  --accent-hover: #0757b8;
  --danger: #cf222e;
  --editor-bg: #d8dee5;
  --focus: #54aeff;
  --control-border-hover: #8c959f;
  --control-bg-hover: #eef1f4;
  --control-min-height: 36px;
  --control-radius: 6px;
  --notice-border: #9cd5ff;
  --notice-text: #0550ae;
  --notice-bg: #ddf4ff;
  --fixed-white: #ffffff;
  --page-shadow: 0 4px 18px rgb(0 0 0 / 28%);
  --dialog-backdrop: rgb(0 0 0 / 55%);
  --editor-stage-height: 820px;
  --editor-stage-mobile-height: 600px;
  --thumbnail-strip-mobile-height: 175px;
}

* {
  box-sizing: border-box;
}

/* Page foundation */
html,
body {
  min-height: 100%;
  margin: 0;
}

body.pdf-editor-page {
  color: var(--text);
  background: var(--page-bg);
}

/* Shared editor controls */
:is(.pdf-editor-workspace, .pdf-editor-signature-dialog) :where(
  button,
  input,
  select,
  textarea
) {
  color: inherit;
  font: inherit;
}

:is(.pdf-editor-workspace, .pdf-editor-signature-dialog) :where(
  button,
  .pdf-editor-button,
  .pdf-editor-tool-button
) {
  min-height: var(--control-min-height);
  border: 1px solid var(--border);
  border-radius: var(--control-radius);
  background: var(--control-bg);
  cursor: pointer;
}

:is(.pdf-editor-workspace, .pdf-editor-signature-dialog) :where(
  button:hover:not(:disabled),
  .pdf-editor-button:hover,
  .pdf-editor-tool-button:hover
) {
  border-color: var(--control-border-hover);
  background: var(--control-bg-hover);
}

:is(.pdf-editor-workspace, .pdf-editor-signature-dialog) :where(
  button:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible,
  .pdf-editor-button:focus-within,
  .pdf-editor-tool-button:focus-visible
) {
  outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent);
  outline-offset: 2px;
}

:is(.pdf-editor-workspace, .pdf-editor-signature-dialog) :where(
  button:disabled,
  [aria-disabled="true"]
) {
  cursor: not-allowed;
  opacity: 0.5;
}

.pdf-editor-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Page header */
.pdf-editor-main {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.pdf-editor-breadcrumb {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.875rem;
}

.pdf-editor-breadcrumb a {
  color: var(--accent);
}

.pdf-editor-page-header h1 {
  margin: 0 0 8px;
  font-size: clamp(1.65rem, 3vw, 2.2rem);
}

.pdf-editor-page-header p {
  margin: 0 0 18px;
  color: var(--muted);
}

.pdf-editor-notice {
  padding: 12px 14px;
  border: 1px solid var(--notice-border);
  border-radius: 7px;
  color: var(--notice-text);
  background: var(--notice-bg);
}

/* Editor workspace */
.pdf-editor-workspace {
  overflow: hidden;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel-bg);
}

.pdf-editor-workspace[data-theme="dark"] {
  color-scheme: dark;
  --panel-bg: #161b22;
  --control-bg: #21262d;
  --text: #f0f6fc;
  --muted: #9da7b3;
  --border: #3d444d;
  --editor-bg: #0d1117;
}

.pdf-editor-file-toolbar,
.pdf-editor-tool-toolbar,
.pdf-editor-page-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
}

.pdf-editor-file-toolbar {
  justify-content: space-between;
}

.pdf-editor-button-row,
.pdf-editor-inspector-buttons,
.pdf-editor-style-buttons,
.pdf-editor-dialog-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pdf-editor-button,
.pdf-editor-tool-button,
.pdf-editor-button-row button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  text-decoration: none;
}

.pdf-editor-button--primary {
  border-color: var(--accent);
  color: var(--fixed-white);
  background: var(--accent);
}

.pdf-editor-button--primary:hover:not(:disabled) {
  border-color: var(--accent-hover);
  color: var(--fixed-white);
  background: var(--accent-hover);
}

.pdf-editor-select-label {
  display: flex;
  align-items: center;
  gap: 7px;
}

:is(.pdf-editor-workspace, .pdf-editor-signature-dialog) :where(
  select,
  input[type="number"],
  textarea
) {
  min-height: var(--control-min-height);
  border: 1px solid var(--border);
  border-radius: var(--control-radius);
  background: var(--control-bg);
}

:is(.pdf-editor-workspace, .pdf-editor-signature-dialog) :where(
  select,
  input[type="number"]
) {
  padding: 5px 28px 5px 8px;
}

.pdf-editor-workspace textarea {
  width: 100%;
  padding: 8px;
  resize: vertical;
}

.pdf-editor-drop-zone {
  display: grid;
  place-items: center;
  min-height: 190px;
  margin: 16px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: var(--control-bg);
}

.pdf-editor-drop-zone.is-dragover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--notice-bg);
}

.pdf-editor-tool-toolbar {
  flex-wrap: wrap;
}

.pdf-editor-tool-button {
  padding: 5px 11px;
}

.pdf-editor-tool-button.is-active {
  border-color: var(--accent);
  color: var(--fixed-white);
  background: var(--accent);
}

/* Editor layout */
.pdf-editor-layout {
  display: grid;
  grid-template-columns: 180px minmax(520px, 1fr) 300px;
  min-height: 720px;
}

.pdf-editor-sidebar,
.pdf-editor-inspector {
  min-width: 0;
  border-right: 1px solid var(--border);
  background: var(--panel-bg);
}

.pdf-editor-inspector {
  overflow: auto;
  max-height: 900px;
  border-right: 0;
  border-left: 1px solid var(--border);
}

.pdf-editor-panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 11px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.pdf-editor-thumbnail-list {
  overflow-y: auto;
  height: var(--editor-stage-height);
  padding: 10px;
}

.pdf-editor-thumbnail {
  display: grid;
  place-items: center;
  width: 100%;
  height: auto;
  margin-bottom: 10px;
  padding: 8px;
  background: var(--control-bg);
}

.pdf-editor-thumbnail[aria-current="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.pdf-editor-thumbnail canvas {
  max-width: 100%;
  background: var(--fixed-white);
}

.pdf-editor-thumbnail span {
  margin-top: 5px;
  font-size: 0.78rem;
}

.pdf-editor-viewer-panel {
  min-width: 0;
  background: var(--editor-bg);
}

.pdf-editor-page-toolbar {
  flex-wrap: wrap;
}

.pdf-editor-page-toolbar button,
.pdf-editor-page-toolbar select,
.pdf-editor-page-toolbar input {
  min-height: 32px;
}

.pdf-editor-page-number-input {
  width: 70px;
}

.pdf-editor-viewer-stage {
  position: relative;
  display: flex;
  overflow: auto;
  align-items: flex-start;
  justify-content: center;
  height: var(--editor-stage-height);
  padding: 16px;
  background: var(--editor-bg);
}

.pdf-editor-page-surface {
  position: relative;
  flex: 0 0 auto;
  line-height: 0;
  box-shadow: var(--page-shadow);
}

.pdf-editor-canvas {
  display: block;
  background: var(--fixed-white);
}

/* Annotation layer */
.pdf-editor-annotation-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: normal;
  touch-action: none;
}

.pdf-editor-annotation {
  position: absolute;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
  color: inherit;
  background: transparent;
  touch-action: none;
}

.pdf-editor-annotation:hover {
  background: transparent;
}

.pdf-editor-annotation[aria-pressed="true"] {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

.pdf-editor-annotation > span:first-child {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
  white-space: pre-wrap;
  text-align: left;
  line-height: 1.35;
}

.pdf-editor-annotation img,
.pdf-editor-annotation svg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.pdf-editor-resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--fixed-white);
  border-radius: 50%;
  background: var(--accent);
}

.pdf-editor-annotation[aria-pressed="true"] .pdf-editor-resize-handle {
  display: block;
}

.pdf-editor-empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
}

/* Inspector and status */
.pdf-editor-inspector-section {
  padding: 13px;
  border-bottom: 1px solid var(--border);
}

.pdf-editor-inspector-section h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.pdf-editor-field-label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.83rem;
}

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

.pdf-editor-style-buttons {
  margin-top: 12px;
}

.pdf-editor-inspector-buttons button {
  flex: 1 1 110px;
}

.pdf-editor-form-fields {
  display: grid;
  gap: 10px;
}

.pdf-editor-form-field {
  display: grid;
  gap: 5px;
  font-size: 0.82rem;
}

.pdf-editor-field-grid .pdf-editor-field-control,
.pdf-editor-form-field input,
.pdf-editor-form-field select {
  width: 100%;
}

.pdf-editor-status-panel {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--panel-bg);
}

.pdf-editor-status-panel progress {
  width: 100%;
}

.pdf-editor-status-panel p {
  margin: 5px 0;
}

.pdf-editor-status-panel [data-type="error"] {
  color: var(--danger);
}

/* Signature dialog */
.pdf-editor-signature-dialog {
  width: min(680px, calc(100% - 24px));
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--panel-bg);
}

.pdf-editor-signature-dialog::backdrop {
  background: var(--dialog-backdrop);
}

.pdf-editor-signature-canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--control-radius);
  background: var(--fixed-white);
  touch-action: none;
}

.pdf-editor-dialog-buttons {
  justify-content: flex-end;
  margin-top: 12px;
}

/* タブレットではインスペクターを編集領域の下へ移動する。 */
@media (max-width: 1050px) {
  .pdf-editor-layout {
    grid-template-columns: 150px minmax(420px, 1fr);
  }

  .pdf-editor-inspector {
    grid-column: 1 / -1;
    max-height: none;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

}

/* モバイルでは各領域を縦に並べ、サムネイルを横スクロールへ切り替える。 */
@media (max-width: 700px) {
  .pdf-editor-main {
    width: min(100% - 16px, 1500px);
    padding-top: 12px;
  }

  .pdf-editor-file-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .pdf-editor-layout {
    display: block;
  }

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

  .pdf-editor-thumbnail-list {
    display: flex;
    height: var(--thumbnail-strip-mobile-height);
    gap: 8px;
  }

  .pdf-editor-thumbnail {
    flex: 0 0 125px;
    margin: 0;
  }

  .pdf-editor-viewer-stage {
    height: var(--editor-stage-mobile-height);
    justify-content: flex-start;
  }

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