:root {
  --bg: #111318;
  --panel: #1a1d24;
  --panel-2: #202530;
  --line: #333a46;
  --text: #f4f6fb;
  --muted: #a9b1c0;
  --accent: #4fb6a8;
  --accent-2: #70a2c8;
  --danger: #ff6b6b;
  --paper: #2a303b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

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

button,
.fileButton,
.tool {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
}

button:hover,
.fileButton:hover,
.tool:hover {
  border-color: var(--accent);
}

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

input[type="text"],
input:not([type]) {
  min-width: 0;
}

input {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #10131a;
  padding: 8px 10px;
}

select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #10131a;
  padding: 6px 8px;
}

.sidebar {
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
}

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

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

.brand h1 {
  margin: 0;
  font-size: 18px;
}

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

.panel {
  border-top: 1px solid var(--line);
  padding: 14px 0;
}

.panelTitle,
.label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

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

.fileButton {
  display: grid;
  place-items: center;
  width: 100%;
  margin-top: 8px;
}

.gridButtons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.workflowButtons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.download {
  display: none;
  margin-top: 10px;
  color: var(--accent);
  text-decoration: none;
}

.download.visible {
  display: inline-block;
}

.workspace {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: #171a21;
  padding: 10px 12px;
}

.toolGroup,
.properties {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tool {
  display: inline-grid;
  place-items: center;
  padding: 0 11px;
  min-width: 48px;
}

.tool.active {
  color: #06110f;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.properties label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.properties input[type="number"] {
  width: 72px;
}

.properties input[type="range"] {
  width: 110px;
  padding: 0;
}

.properties input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
  accent-color: var(--accent);
}

.checkLabel {
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #10131a;
  white-space: nowrap;
}

#blendImageBtn {
  border-color: rgba(112, 162, 200, 0.72);
}

#deleteOverlayBtn {
  color: var(--danger);
}

.dangerButton {
  width: 100%;
  margin-top: 8px;
  color: var(--danger);
}

#boldBtn,
#italicBtn {
  width: 36px;
  font-weight: 800;
}

#italicBtn {
  font-style: italic;
}

#boldBtn.active,
#italicBtn.active {
  color: #06110f;
  background: var(--accent);
  border-color: var(--accent);
}

.stageWrap {
  min-height: 0;
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr);
}

.thumbs {
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #131720;
  padding: 10px;
}

.thumb {
  display: grid;
  gap: 6px;
  width: 100%;
  margin-bottom: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}

.thumb.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.thumb img {
  width: 100%;
  height: 120px;
  object-fit: contain;
  background: #0e1117;
}

.thumb span {
  color: var(--muted);
  font-size: 12px;
  text-align: left;
}

.stageShell {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: start center;
  padding: 28px;
  background: #0f1218;
}

.emptyState {
  margin-top: 14vh;
  max-width: 460px;
  text-align: center;
  color: var(--muted);
}

.emptyState h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 24px;
}

.stage {
  position: relative;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  background: var(--paper);
}

#pageImage,
#overlayCanvas {
  display: block;
  max-width: min(100%, 1100px);
}

#overlayCanvas {
  position: absolute;
  inset: 0;
  cursor: crosshair;
}

#inlineEditor {
  position: absolute;
  z-index: 4;
  resize: none;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--accent);
  outline: 2px solid rgba(79, 182, 168, 0.3);
  background: transparent;
  padding: 0;
  color: inherit;
  line-height: 1.08;
  white-space: pre;
  caret-color: currentColor;
}

.workspaceDialog {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--panel);
  padding: 0;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.58);
}

.wideDialog {
  width: min(980px, calc(100vw - 32px));
}

.workspaceDialog::backdrop {
  background: rgba(5, 7, 10, 0.72);
}

.dialogHeader,
.dialogFooter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #171a21;
}

.dialogHeader {
  border-bottom: 1px solid var(--line);
}

.dialogFooter {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

.dialogHeader h2,
.conversionSection h3 {
  margin: 0;
}

.dialogHeader h2 {
  font-size: 18px;
}

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

.dialogBody {
  max-height: calc(100vh - 168px);
  overflow: auto;
  padding: 16px;
}

.dialogBody > label,
.fieldGrid label,
.conversionSection > label,
.signaturePanel > label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.dialogBody textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #10131a;
  padding: 10px;
  line-height: 1.45;
}

.fieldGrid {
  display: grid;
  gap: 12px;
  margin: 12px 0;
}

.twoColumns {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.fieldGrid input,
.fieldGrid select,
.conversionSection select {
  width: 100%;
}

.iconButton {
  width: 36px;
  min-width: 36px;
}

.primaryButton {
  color: #06110f;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.signaturePanel {
  margin: 12px 0;
}

#signaturePad {
  display: block;
  width: 100%;
  aspect-ratio: 760 / 220;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  touch-action: none;
}

.signaturePreview {
  display: grid;
  place-items: center;
  min-height: 128px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #17202a;
  background: #ffffff;
  font-family: "Segoe Script", cursive;
  font-size: 48px;
}

.inlineOptions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.resultList {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.resultRow {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding: 10px 0 2px;
}

.resultRow strong,
.resultRow span {
  display: block;
}

.resultRow span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.confidence {
  min-width: 66px;
  color: var(--accent);
  text-align: right;
  font-size: 12px;
}

.conversionLayout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.conversionSection {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  border-left: 1px solid var(--line);
  padding-left: 16px;
}

.conversionSection:first-child {
  border-left: 0;
  padding-left: 0;
}

.conversionSection h3 {
  font-size: 15px;
}

.conversionSection .twoColumns {
  grid-template-columns: 1fr;
  margin: 0;
}

.conversionLayout .download {
  grid-column: 1 / -1;
}

.conversionReport {
  grid-column: 1 / -1;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.conversionProgress {
  display: block;
  width: min(520px, 100%);
  height: 10px;
  accent-color: var(--accent);
}

.conversionReport p { margin: 6px 0; }
.conversionReport .conversionWarning { color: #edc779; }
#wordModeField[hidden], #wordModeNote[hidden], .conversionReport[hidden] { display: none; }

.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 32px;
  border-top: 1px solid var(--line);
  background: #171a21;
  color: var(--muted);
  padding: 7px 12px;
  font-size: 12px;
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

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

  .workspace {
    height: auto;
    min-height: 70vh;
  }

  .stageWrap {
    grid-template-columns: 112px minmax(0, 1fr);
  }

  .conversionLayout,
  .twoColumns {
    grid-template-columns: 1fr;
  }

  .conversionSection {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 14px 0 0;
  }

  .conversionSection:first-child {
    border-top: 0;
    padding-top: 0;
  }
}
