html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: #eef1f4;
  color: #1f2937;
}

body {
  overflow: hidden;
}

.topbar {
  height: 64px;
  box-sizing: border-box;
  background: #1f2937;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  direction: rtl;
}

.topbar-right,
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.upload-label {
  background: #2563eb;
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

#pdfUpload {
  display: none;
}

.page-info {
  font-size: 14px;
  font-weight: 700;
  opacity: 0.95;
}

.layout {
  height: calc(100vh - 64px);
  display: flex;
  flex-direction: row-reverse;
}

.toolbar {
  width: 360px;
  min-width: 360px;
  max-width: 360px;
  background: #ffffff;
  border-left: 1px solid #d7dce2;
  overflow-y: auto;
  padding: 16px;
  box-sizing: border-box;
  direction: rtl;
}

.panel {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.panel h2 {
  margin: 0 0 12px 0;
  font-size: 17px;
  font-weight: 800;
}

.panel label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
}

.panel input,
.panel select,
.panel button {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 10px;
  border-radius: 8px;
  font: inherit;
}

.panel input,
.panel select {
  padding: 10px 12px;
  border: 1px solid #cfd6dd;
  background: #ffffff;
}

.panel button {
  padding: 10px 12px;
  border: none;
  background: #334155;
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.panel button:hover {
  opacity: 0.94;
}

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

.button-row .danger {
  background: #b91c1c;
}

.success {
  background: #15803d !important;
}

.primary {
  background: #1d4ed8 !important;
}

.danger {
  background: #b91c1c !important;
}

.note {
  font-size: 13px;
  line-height: 1.5;
  color: #475569;
  margin-top: 4px;
}

.tool-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.tool-item {
  text-align: right;
}

.panel-docs { background: #eef4ff; }
.panel-templates { background: #f5f3ff; }
.panel-fid { background: #ecfeff; }
.panel-general { background: #f3f4f6; }
.panel-customer { background: #ecfdf5; }
.panel-adviser { background: #fdf2f8; }
.panel-selected { background: #fff7ed; }
.panel-nav { background: #f8fafc; }

.workspace {
  flex: 1;
  height: 100%;
  overflow: auto;
  padding: 24px;
  box-sizing: border-box;
  direction: ltr;
}

.pages-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  min-height: 100%;
}

.page-shell {
  position: relative;
  background: #ffffff;
  box-shadow: 0 2px 14px rgba(0,0,0,0.12);
  border: 3px solid transparent;
  border-radius: 4px;
}

.page-shell.active-page {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15), 0 2px 14px rgba(0,0,0,0.12);
}

.page-meta {
  position: absolute;
  top: -30px;
  right: 0;
  background: #2563eb;
  color: #ffffff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 700;
}

.page-canvas {
  display: block;
  background: #ffffff;
}

.page-overlay {
  position: absolute;
  inset: 0;
}

.field-box {
  position: absolute;
  border: 2px dashed #475569;
  background: rgba(255,255,255,0.92);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  cursor: move;
  user-select: none;
  overflow: visible;
}

.field-box.selected {
  border: 2px solid #f97316;
  box-shadow: 0 0 0 2px rgba(249,115,22,0.18);
}

.field-label {
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 700;
  color: #1f2937;
  text-align: center;
  width: 100%;
  box-sizing: border-box;
  pointer-events: none;
}

.field-box[data-type="title"] .field-label {
  font-size: 24px;
  font-weight: 800;
}

.field-box[data-type="checkbox"] .field-label {
  font-size: 16px;
}

.field-box[data-type="signature"] .field-label {
  font-style: italic;
}

.resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  right: -8px;
  bottom: -8px;
  background: #2563eb;
  border: 2px solid #ffffff;
  border-radius: 50%;
  cursor: nwse-resize;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.field-box.selected .resize-handle {
  background: #f97316;
}
