:root {
  --primary: #1351b4;
  --primary-hover: #0c326f;
  --primary-light: #e8f0fe;
  --gov-blue: #0c326f;
  --gov-accent: #1351b4;
  --success: #16a34a;
  --danger: #dc2626;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  height: 64px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #1351b4 0%, #0c326f 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.header-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gov-blue);
  line-height: 1.2;
}

.header-brand h1 span {
  color: var(--primary);
  font-weight: 800;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Layout Principal */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 64px);
}

/* Sidebar */
.sidebar {
  width: 380px;
  min-width: 340px;
  max-width: 420px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-step {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-step-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-step-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Dropzones */
.dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-sm);
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
  background: #f8fafc;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.dropzone-compact {
  padding: 12px 8px;
}

.dropzone-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.dropzone-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Checkerboard e Preview da Assinatura */
.sig-preview-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sig-checkerboard {
  background-color: #ffffff;
  background-image: 
    linear-gradient(45deg, #f1f5f9 25%, transparent 25%), 
    linear-gradient(-45deg, #f1f5f9 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #f1f5f9 75%), 
    linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.sig-checkerboard img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.sig-preview-controls {
  display: flex;
  justify-content: space-between;
}

/* Opções e Toggles */
.options-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border-color);
  padding-top: 8px;
}

.toggle-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
}

.toggle-option input[type="checkbox"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
}

.range-control {
  margin-left: 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.range-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.range-control input[type="range"] {
  accent-color: var(--primary);
  cursor: pointer;
}

/* Lista de PDFs */
.pdf-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}

.pdf-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.pdf-items {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pdf-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pdf-item:hover, .pdf-item.active {
  background: var(--primary-light);
  border-color: var(--primary);
}

.pdf-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
  font-weight: 500;
}

.pdf-item-remove {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}

.pdf-item-remove:hover {
  color: var(--danger);
  background: #fee2e2;
}

/* Radio Group */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.82rem;
  cursor: pointer;
}

.radio-option input[type="radio"] {
  accent-color: var(--primary);
  margin-top: 3px;
}

.radio-option div strong {
  display: block;
  font-size: 0.83rem;
  color: var(--text-main);
}

.radio-option div small {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.section-divider {
  height: 1px;
  background: var(--border-color);
  margin: 4px 0;
}

.field-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
  display: block;
  margin-bottom: 6px;
}

/* Biblioteca de Assinantes na Sidebar */
.signers-library-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 190px;
  overflow-y: auto;
}

.signer-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.signer-chip:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.signer-chip-info {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.signer-chip-thumb {
  width: 44px;
  height: 24px;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  object-fit: contain;
  flex-shrink: 0;
}

.signer-chip-names {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.signer-chip-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.signer-chip-role {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

/* Lista de Assinaturas Ativas na Folha */
.active-sigs-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.active-sig-card {
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all 0.15s ease;
}

.active-sig-card.selected {
  border-color: #3b82f6;
  border-left-color: #1d4ed8;
  background: var(--primary-light);
}

.active-sig-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.active-sig-card-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
}

.active-sig-card-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.active-sig-select {
  font-size: 0.72rem;
  padding: 2px 4px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: white;
}

.empty-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  padding: 10px 4px;
  line-height: 1.4;
}

.badge-count {
  background: #e0e7ff;
  color: #3730a3;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: auto;
}

/* Formulários nos Modais */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-input {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  font-family: inherit;
}

.form-input:focus {
  border-color: var(--border-focus);
}

.manager-signers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  max-height: 50vh;
  overflow-y: auto;
}

.manager-signer-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: white;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.manager-signer-thumb {
  height: 60px;
  background-color: #f8fafc;
  background-image: 
    linear-gradient(45deg, #f1f5f9 25%, transparent 25%), 
    linear-gradient(-45deg, #f1f5f9 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #f1f5f9 75%), 
    linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
  background-size: 8px 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.manager-signer-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.ml-auto {
  margin-left: auto;
}

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }

.text-sm { font-size: 0.82rem; }


.preset-buttons {
  display: flex;
  gap: 6px;
}

.btn-preset {
  flex: 1;
  border: 1px solid var(--border-color);
  background: #f8fafc;
  font-size: 0.75rem;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-preset.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.hint-text {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Texto Adicional */
.text-addition-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.text-fields-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.text-fields-container textarea {
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-family: inherit;
  font-size: 0.8rem;
  resize: vertical;
}

.text-fields-container textarea:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 0.72rem;
}

.btn-lg {
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-gov {
  background: #0c326f;
  color: white;
  font-weight: 600;
}

.btn-gov:hover {
  background: #08214d;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover:not(:disabled) {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: #f1f5f9;
  color: var(--text-main);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-icon:hover:not(:disabled) {
  background: #f1f5f9;
}

.action-card {
  margin-top: auto;
  background: #eff6ff;
  border-color: #bfdbfe;
}

.action-hint {
  font-size: 0.72rem;
  text-align: center;
  color: var(--text-muted);
}

/* Área Central do Visualizador */
.viewer-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #64748b;
  overflow: hidden;
}

.viewer-toolbar {
  height: 48px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 5;
}

.viewer-doc-info {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-pagination, .viewer-zoom {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 500;
}

.viewport-container {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px;
  position: relative;
}

.empty-state {
  margin-top: 100px;
  background: white;
  border-radius: var(--radius-lg);
  padding: 40px;
  max-width: 480px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #f1f5f9;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-main);
}

.empty-state p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Palco da Folha do PDF */
.page-stage-wrapper {
  display: inline-block;
  margin: auto;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

.page-stage {
  position: relative;
  background: white;
  line-height: 0;
  user-select: none;
}

#pdfCanvas {
  display: block;
}

/* Overlay da Assinatura Interativa */
.sig-overlay {
  position: absolute;
  border: 2px dashed #2563eb;
  background: rgba(37, 99, 235, 0.08);
  cursor: move;
  z-index: 10;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.sig-overlay:hover, .sig-overlay.dragging {
  border-color: #1d4ed8;
  background: rgba(37, 99, 235, 0.15);
}

.sig-overlay-body {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
}

.sig-overlay-body img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.sig-overlay-caption {
  display: none !important;
}

.sig-badge {
  position: absolute;
  top: -24px;
  left: -2px;
  background: #1e293b;
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  opacity: 0.85;
}

/* Alças de Redimensionamento */
.sig-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: white;
  border: 2px solid #1d4ed8;
  border-radius: 2px;
  z-index: 12;
}

.handle-br {
  right: -5px;
  bottom: -5px;
  cursor: se-resize;
}

.handle-bl {
  left: -5px;
  bottom: -5px;
  cursor: sw-resize;
}

.handle-tr {
  right: -5px;
  top: -5px;
  cursor: ne-resize;
}

.handle-tl {
  left: -5px;
  top: -5px;
  cursor: nw-resize;
}

/* Modais / Dialogs */
.modal-dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 580px;
  width: 90vw;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  margin: auto;
}

.modal-dialog::backdrop {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 1.15rem;
  color: var(--gov-blue);
  font-weight: 700;
}

.modal-body {
  padding: 24px;
  max-height: 70vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: #f8fafc;
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

.gov-intro {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-main);
}

.gov-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gov-steps li {
  display: flex;
  gap: 14px;
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e0e7ff;
  color: #3730a3;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.gov-steps li strong {
  display: block;
  font-size: 0.9rem;
  color: var(--text-main);
  margin-bottom: 2px;
}

.gov-steps li p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.gov-steps a {
  color: var(--primary);
  font-weight: 600;
}

.success-banner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

.success-banner h3 {
  font-size: 1.15rem;
  color: var(--text-main);
}

.success-banner p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.gov-next-step {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gov-next-step h4 {
  font-size: 0.9rem;
  color: #166534;
}

.gov-next-step p {
  font-size: 0.82rem;
  color: #15803d;
}

.gov-callout {
  margin-top: 6px;
}

/* Utilitários */
.hidden {
  display: none !important;
}
