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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  background: #525659;
}

/* ── Toolbar ── */
#toolbar {
  flex: 0 0 auto;
  background: #1a3a6b;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 54px;
  gap: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
  z-index: 10;
}

#toolbar h1 {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#toolbar h1 small {
  font-weight: 400;
  opacity: 0.7;
  margin-left: 6px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#save-indicator {
  font-size: 0.75rem;
  white-space: nowrap;
  transition: color 0.3s;
}
#save-indicator::before { content: '● '; }
#save-indicator.saved   { color: #86efac; }
#save-indicator.unsaved { color: #fbbf24; }
#save-indicator.saving  { color: #93c5fd; }

button {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

button.primary       { background: #2563eb; color: #fff; }
button.primary:hover { background: #1d4ed8; }
#btn-clear           { background: rgba(255,255,255,0.15); color: #fff; }
#btn-clear:hover     { background: rgba(255,255,255,0.25); }

/* ── Main content area ── */
.main-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Loading & Error ── */
#loading-state,
#error-state {
  position: absolute;
  inset: 0;
  /* display:flex only when NOT hidden — ID selectors beat [hidden]{display:none} otherwise */
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #ccc;
  text-align: center;
  padding: 24px;
  background: #525659;
}

#loading-state:not([hidden]),
#error-state:not([hidden]) {
  display: flex;
}

#error-state { color: #fca5a5; }

#error-state small {
  display: block;
  margin-top: 6px;
  color: #f87171;
  font-size: 0.8rem;
  max-width: 320px;
  line-height: 1.5;
}

#error-state code {
  background: rgba(255,255,255,0.1);
  padding: 2px 5px;
  border-radius: 4px;
}

#error-state button {
  margin-top: 8px;
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── PDF Viewer ── */
#viewerContainer {
  position: absolute;
  inset: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.pdfViewer .page {
  margin: 16px auto;
}

/* ── Restore banner ── */
#restore-banner {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 32px));
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  z-index: 100;
  text-align: center;
}

#restore-banner p {
  font-size: 0.9rem;
  color: #374151;
  margin-bottom: 14px;
}

.banner-actions {
  display: flex;
  gap: 10px;
}

.banner-actions button { flex: 1; }
#btn-discard { background: #f3f4f6; color: #374151; }
#btn-discard:hover { background: #e5e7eb; }

/* ── Print ── */
@media print {
  /* Hide all chrome — only PDF pages should print */
  #toolbar, #restore-banner,
  #loading-state, #error-state { display: none !important; }

  html, body {
    height: auto !important;
    overflow: visible !important;
    background: white !important;
  }

  /* Keep .main-content positioned so absolute children stay contained */
  .main-content {
    position: relative !important;
    height: auto !important;
    overflow: visible !important;
    background: white !important;
  }

  #viewerContainer {
    position: static !important;
    height: auto !important;
    overflow: visible !important;
    background: white !important;
  }

  .pdfViewer {
    background: white !important;
  }

  .pdfViewer .page {
    margin: 0 !important;
    border: none !important;
    box-shadow: none !important;
    page-break-after: always;
    break-after: page;
  }
}

/* ── Launch Screen ── */
#launch-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #525659;
  padding: 24px;
  z-index: 300;
}

#launch-screen[hidden] { display: none; }

.launch-cards {
  display: flex;
  gap: 20px;
  max-width: 580px;
  width: 100%;
  align-items: stretch;
}

.launch-card {
  flex: 1;
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.launch-card-icon {
  width: 52px;
  height: 52px;
  color: #1a3a6b;
  margin-bottom: 2px;
}

.launch-card-icon svg {
  width: 100%;
  height: 100%;
}

.launch-card h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: #111827;
}

.launch-card p {
  font-size: 0.85rem;
  color: #6b7280;
  line-height: 1.4;
  flex: 1;
}

.launch-card-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}

.launch-card-actions button { width: 100%; }

.draft-ts {
  font-size: 0.75rem;
  color: #9ca3af;
  margin: -2px 0;
}

.launch-divider {
  width: 1px;
  background: rgba(255,255,255,0.2);
  flex-shrink: 0;
  align-self: stretch;
}

@media (max-width: 520px) {
  .launch-cards {
    flex-direction: column;
    max-height: calc(100dvh - 48px);
    overflow-y: auto;
  }
  .launch-divider {
    width: 100%;
    height: 1px;
  }
}

/* ── Download ready banner ── */
#download-ready {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 32px));
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  z-index: 200;
  text-align: center;
}
#download-ready p {
  font-size: 0.9rem;
  color: #374151;
  margin-bottom: 12px;
}
#download-ready a {
  display: inline-block;
  background: #2563eb;
  color: #fff;
  text-decoration: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}
#download-ready a:hover { background: #1d4ed8; }
#download-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  color: #9ca3af;
  font-size: 1rem;
  padding: 4px 6px;
}
#download-close:hover { color: #374151; }

/* ── Signature Modal ── */
#sig-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  padding: 16px;
}
#sig-modal[hidden] { display: none; }

#sig-panel {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  width: min(520px, 100%);
  box-shadow: 0 12px 48px rgba(0,0,0,0.3);
}

#sig-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

#sig-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #111827;
}

#sig-canvas {
  display: block;
  width: 100%;
  height: 180px;
  border: 1.5px solid #d1d5db;
  border-radius: 8px;
  touch-action: none;
  cursor: crosshair;
  background: #fff;
}

#sig-hint {
  font-size: 0.75rem;
  color: #9ca3af;
  text-align: center;
  margin-top: 6px;
}

#sig-footer {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  justify-content: flex-end;
}

#sig-footer button { min-width: 80px; }

/* ── Mobile ── */
@media (max-width: 520px) {
  #toolbar h1 small { display: none; }
  button { padding: 7px 10px; font-size: 0.8rem; }
  #save-indicator { display: none; }
}

/* ── Checkbox appearance fix ── */
/* PDF.js 4.x draws checked checkboxes as two ±45° rotated lines (an X).
   Override to show a proper checkmark instead. */
.annotationLayer .buttonWidgetAnnotation.checkBox input:checked::before,
.annotationLayer .buttonWidgetAnnotation.checkBox input:checked::after {
  display: none !important;
}
.annotationLayer .buttonWidgetAnnotation.checkBox input:checked {
  background-color: transparent !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2,6.5L4.5,9L10,3.5' stroke='%23000' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: center !important;
  background-size: 80% !important;
}
/* Remove the red required-field outline — this is a viewer, not a form validator */
.annotationLayer .buttonWidgetAnnotation.checkBox input,
.annotationLayer .buttonWidgetAnnotation.radioButton input {
  outline: none !important;
}
