* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.upload-btn {
  display: inline-block;
  padding: 6px 14px;
  background: #4a90d9;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.upload-btn:hover {
  background: #3a7bc8;
}

#downloadBtn {
  padding: 6px 14px;
  background: #34a853;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

#downloadBtn:hover:not(:disabled) {
  background: #2d9249;
}

#downloadBtn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Preview panel */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #e8e8e8;
  overflow: hidden;
}

.canvas-container {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  cursor: grab;
}

#pdfCanvas {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  background: #fff;
}

.canvas-container {
  touch-action: pan-x pan-y;
}

.page-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px;
  background: #fff;
  border-top: 1px solid #ddd;
}

.page-nav button {
  padding: 4px 12px;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.page-nav button:hover:not(:disabled) {
  background: #f0f0f0;
}

.page-nav button:disabled {
  color: #aaa;
  cursor: not-allowed;
}

#pageInfo {
  font-size: 13px;
  color: #666;
  min-width: 80px;
  text-align: center;
}

.nav-divider {
  color: #ccc;
  margin: 0 4px;
}

#zoomSlider {
  width: 100px;
  vertical-align: middle;
}

#zoomValue {
  font-size: 13px;
  color: #666;
  min-width: 40px;
  display: inline-block;
}

/* Controls panel */
.controls-panel {
  width: 320px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 16px;
  background: #fff;
  border-left: 1px solid #ddd;
}

.control-group {
  margin-bottom: 14px;
}

.control-group label {
  font-size: 13px;
  color: #555;
}

.text-input-row {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.text-input-row input[type="text"] {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
}

.text-input-row button {
  padding: 6px 12px;
  background: #4a90d9;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

.text-input-row button:hover {
  background: #3a7bc8;
}

.grid-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.grid-field {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.grid-label {
  font-size: 11px;
  color: #888;
  margin-bottom: 2px;
}

.grid-field input[type="number"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
}

.grid-x {
  font-size: 14px;
  color: #999;
  margin-top: 14px;
}

.grid-input-row button {
  padding: 6px 12px;
  background: #4a90d9;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  margin-top: 14px;
}

.grid-input-row button:hover {
  background: #3a7bc8;
}

.grid-hint {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.slider-value {
  font-size: 13px;
  font-weight: 600;
  color: #333;
}

input[type="range"] {
  width: 100%;
  cursor: pointer;
  accent-color: #4a90d9;
}

input[type="color"] {
  width: 100%;
  height: 32px;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  padding: 2px;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
}

.checkbox-group .hint {
  font-size: 12px;
  color: #999;
}

.config-preview {
  margin-top: 16px;
  padding: 12px;
  background: #f5f5f5;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
}

.config-preview pre {
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Consolas', monospace;
  font-size: 11px;
  line-height: 1.5;
  color: #444;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Loading overlay */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  font-weight: 500;
  z-index: 100;
}

.loading.hidden {
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  main {
    flex-direction: column;
  }

  .controls-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid #ddd;
    max-height: 50vh;
  }
}
