/* Adobe-inspired dark UI */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 12px;
  color: #d6d6d6;
  background: #1d1d1d;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Layout shell */
.app { display: grid; grid-template-rows: 40px 1fr; height: 100vh; }

.titlebar {
  background: linear-gradient(#383838, #2c2c2c);
  border-bottom: 1px solid #0c0c0c;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  background: #2680eb; color: #fff; border-radius: 3px;
  font-weight: 700; font-size: 11px; letter-spacing: 0.5px;
}
.title { font-weight: 600; font-size: 13px; color: #f2f2f2; }
.subtitle { color: #8a8a8a; font-size: 12px; padding-left: 6px; border-left: 1px solid #444; }
.actions { display: flex; gap: 6px; align-items: center; }
.lang-select {
  background: #3a3a3a; color: #d6d6d6;
  border: 1px solid #1a1a1a; border-radius: 3px;
  padding: 4px 22px 4px 8px;
  font-size: 11.5px; font-family: inherit;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #999 50%), linear-gradient(135deg, #999 50%, transparent 50%);
  background-position: calc(100% - 12px) 50%, calc(100% - 8px) 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.lang-select:hover { background-color: #444; }

/* Buttons */
.btn {
  background: #444; color: #e6e6e6;
  border: 1px solid #1a1a1a;
  padding: 5px 12px; border-radius: 3px;
  font-size: 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: #555; }
.btn:active { background: #333; }
.btn.primary { background: #2680eb; border-color: #1567c8; color: #fff; }
.btn.primary:hover:not(:disabled) { background: #2c8df0; }
.btn.primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.ghost { background: transparent; border: 1px solid #555; }
.btn.ghost:hover { background: #2f2f2f; }
.btn.full { width: 100%; justify-content: center; }
.btn .ico { font-size: 13px; }

/* Workspace 3-pane */
.workspace {
  display: grid;
  grid-template-columns: 260px 1fr 290px;
  height: calc(100vh - 40px);
  min-height: 0;
}

.panel {
  background: #2a2a2a;
  border-left: 1px solid #0c0c0c;
  border-right: 1px solid #0c0c0c;
  overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #555 #2a2a2a;
}
.panel.left { border-left: none; }
.panel.right { border-right: none; }
.panel::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }
.panel::-webkit-scrollbar-track { background: #2a2a2a; }

.panel-header {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px;
  color: #b6b6b6; padding: 10px 12px;
  border-bottom: 1px solid #1a1a1a; background: #303030;
  position: sticky; top: 0; z-index: 1;
}

/* Sections (collapsible) */
.section {
  border-bottom: 1px solid #1a1a1a;
  padding: 10px 12px;
}
.section[open] > summary::before { transform: rotate(90deg); }
.section > summary {
  cursor: pointer;
  list-style: none;
  display: flex; align-items: center; gap: 6px;
  padding: 2px 0 8px;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before {
  content: "▶"; color: #777; font-size: 9px; transition: transform 0.12s ease;
  display: inline-block;
}
.section-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.8px;
  color: #c8c8c8; font-weight: 600;
}
summary.section-title { padding-left: 0; }

.row { display: block; padding: 5px 0; }
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row.btnrow { padding-top: 8px; }
.row.check { padding: 4px 0; }
.row label {
  display: block;
  color: #999; font-size: 10.5px;
  margin-bottom: 3px;
  text-transform: uppercase; letter-spacing: 0.5px;
}

/* Controls */
.ctl {
  width: 100%;
  background: #1f1f1f;
  color: #e6e6e6;
  border: 1px solid #0c0c0c;
  outline: 1px solid #4a4a4a;
  outline-offset: -1px;
  border-radius: 2px;
  padding: 5px 7px;
  font-size: 12px;
  font-family: inherit;
}
.ctl:focus { outline-color: #2680eb; }
.ctl:disabled { opacity: 0.45; }
select.ctl {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #999 50%), linear-gradient(135deg, #999 50%, transparent 50%);
  background-position: calc(100% - 12px) 50%, calc(100% - 8px) 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  padding-right: 22px;
}
.numwrap { position: relative; }
.numwrap .unit {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  color: #777; font-size: 10.5px; pointer-events: none;
}
.numwrap .ctl.num { padding-right: 22px; text-align: right; }
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { opacity: 0; }

.value { padding: 4px 0; color: #e6e6e6; font-size: 12px; }
.hint { color: #888; line-height: 1.45; font-size: 11.5px; }

/* Checkbox */
.chk { display: flex; align-items: center; gap: 7px; cursor: pointer; color: #d6d6d6 !important; text-transform: none !important; letter-spacing: 0 !important; font-size: 12px !important; }
.chk input[type=checkbox] {
  appearance: none; -webkit-appearance: none;
  width: 13px; height: 13px;
  background: #1f1f1f;
  border: 1px solid #555;
  border-radius: 2px;
  display: inline-block;
  position: relative;
  cursor: pointer;
  flex: 0 0 auto;
}
.chk input[type=checkbox]:checked {
  background: #2680eb; border-color: #2680eb;
}
.chk input[type=checkbox]:checked::after {
  content: "✓"; color: #fff; font-size: 10px; font-weight: 700;
  position: absolute; left: 1px; top: -1px;
}

/* Segmented control */
.seg { display: inline-flex; border: 1px solid #1a1a1a; border-radius: 3px; overflow: hidden; }
.seg-btn {
  background: #3a3a3a; color: #d0d0d0;
  border: none; border-right: 1px solid #1a1a1a;
  padding: 5px 10px; font-size: 11.5px;
  cursor: pointer;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: #444; }
.seg-btn.active { background: #2680eb; color: #fff; }
.seg.small .seg-btn { padding: 4px 8px; font-size: 11px; }

/* Dropzone */
.dropzone {
  border: 1.5px dashed #555;
  border-radius: 4px;
  padding: 22px 14px;
  text-align: center;
  cursor: pointer;
  background: #232323;
  color: #aaa;
  transition: all 0.12s ease;
}
.dropzone:hover, .dropzone.drag {
  border-color: #2680eb; color: #fff; background: #1f2a3d;
}
.dropzone .dz-icon { font-size: 28px; line-height: 1; margin-bottom: 8px; }
.dropzone .dz-title { font-size: 12.5px; font-weight: 600; }
.dropzone .dz-sub { font-size: 11.5px; color: #777; margin-top: 4px; }
.dropzone a { color: #2680eb; text-decoration: none; }

/* PDF thumbs */
.thumbs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  margin-top: 8px;
}
.thumb {
  background: #1a1a1a; border: 1px solid #1a1a1a;
  outline: 1px solid #444; outline-offset: -1px;
  cursor: pointer; padding: 3px;
  transition: outline-color 0.1s ease;
  aspect-ratio: 0.7;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.thumb canvas { max-width: 100%; max-height: 100%; }
.thumb.active { outline-color: #2680eb; outline-width: 2px; }
.thumb .num {
  position: absolute; top: 1px; left: 3px; font-size: 9.5px;
  color: #999; font-family: ui-monospace, monospace;
}

/* Margins grid icon */
.margins-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto auto;
  grid-template-areas:
    ".  top    ."
    "left center right"
    ".  bottom .";
  gap: 6px 8px;
  margin-top: 6px;
  align-items: center;
}
.mg-cell label { text-align: center; }
.mg-top { grid-area: top; }
.mg-bottom { grid-area: bottom; }
.mg-left { grid-area: left; }
.mg-right { grid-area: right; }
.mg-center { grid-area: center; display: flex; align-items: center; justify-content: center; padding: 0 2px; }
.paper-icon {
  width: 30px; height: 40px;
  background: #1f1f1f;
  border: 1px solid #555;
  outline: 4px solid #1f1f1f;
  outline-offset: 0;
  position: relative;
}
.paper-icon::before {
  content: "";
  position: absolute; inset: 5px;
  background: #2680eb22;
  border: 1px dashed #2680eb88;
}

/* Canvas area */
.canvas-area {
  display: grid; grid-template-rows: 36px 1fr 24px;
  background: #1d1d1d;
  min-width: 0;
}
.canvas-toolbar {
  background: #2a2a2a;
  border-bottom: 1px solid #1a1a1a;
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px;
}
.canvas-toolbar .spacer { flex: 1; }
.hint-inline {
  color: #666; font-size: 11px;
  white-space: nowrap;
  margin-right: 10px;
}
.zoomctl { display: flex; align-items: center; gap: 4px; }
.zoomval { min-width: 50px; text-align: center; color: #aaa; font-size: 11.5px; }
.icobtn {
  width: 24px; height: 24px;
  background: #3a3a3a; color: #d0d0d0;
  border: 1px solid #1a1a1a; border-radius: 2px;
  cursor: pointer; padding: 0; font-size: 13px; line-height: 1;
}
.icobtn:hover { background: #444; }

.canvas-host {
  position: relative;
  background:
    linear-gradient(45deg, #161616 25%, transparent 25%) 0 0/16px 16px,
    linear-gradient(-45deg, #161616 25%, transparent 25%) 0 0/16px 16px,
    linear-gradient(45deg, transparent 75%, #161616 75%) 0 0/16px 16px,
    linear-gradient(-45deg, transparent 75%, #161616 75%) 0 0/16px 16px,
    #1d1d1d;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.canvas-host.has-content { cursor: grab; }
.canvas-host.dragging { cursor: grabbing; }
.canvas-host:not(.has-content) { cursor: default; }
.canvas-host canvas { display: block; width: 100%; height: 100%; }
.canvas-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #666; pointer-events: none;
}
.canvas-empty .ce-title { font-size: 14px; font-weight: 500; margin-bottom: 4px; color: #888; }
.canvas-empty .ce-sub { font-size: 12px; }

.status-bar {
  background: #2a2a2a;
  border-top: 1px solid #1a1a1a;
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  color: #888; font-size: 11px;
}
.status-bar .dot { color: #555; }

/* Busy overlay */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; z-index: 10;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid #555; border-top-color: #2680eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.busy-text { color: #ddd; font-size: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Hidden helper */
[hidden] { display: none !important; }
