/* ── Reset & Base ─────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: Arial, sans-serif;
  background: #f0f2f5;
  color: #333;
  min-height: 100vh;
}

/* ── Load Screen ──────────────────────────────────────────────────────────── */
#load-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

.load-screen-nav {
  width: 100%;
  background: #1a1a2e;
  padding: 0 28px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  align-self: stretch;
}

.load-screen-nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.load-center {
  width: 100%;
  max-width: 560px;
  text-align: center;
  padding: 60px 20px 40px;
}

.load-logo {
  font-size: 28px;
  font-weight: bold;
  color: #1a1a2e;
  margin-bottom: 20px;
}

.load-center h2 {
  font-size: 26px;
  color: #1a1a2e;
  margin-bottom: 8px;
}

.load-sub {
  color: #666;
  font-size: 14px;
  margin-bottom: 28px;
}

/* Drop Zone */
#drop-zone {
  border: 2px dashed #c0c8d8;
  border-radius: 12px;
  background: white;
  padding: 40px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

#drop-zone:hover,
#drop-zone.drag-over {
  border-color: #4a90e2;
  background: #f0f6ff;
}

.drop-icon { font-size: 40px; }
#drop-zone p { color: #666; font-size: 14px; }
.drop-or { color: #bbb; font-size: 13px; }

.load-btn {
  margin-top: 4px;
  padding: 10px 24px;
  background: #4a90e2;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.load-btn:hover { background: #357abd; }

/* My Forms */
#my-forms-section {
  margin-top: 36px;
  text-align: left;
}

#my-forms-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #999;
  margin-bottom: 10px;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: white;
  border-radius: 8px;
  margin-bottom: 6px;
  border: 1px solid #e8eaed;
  transition: border-color 0.15s;
}

.form-row:hover { border-color: #4a90e2; }

.form-row-title {
  font-size: 14px;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.open-form-btn {
  padding: 6px 14px;
  background: #4a90e2;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}
.open-form-btn:hover { background: #357abd; }

.loading-text, .no-forms {
  color: #bbb;
  font-size: 13px;
  padding: 16px 0;
  text-align: center;
}

.login-nudge {
  margin-top: 28px;
  font-size: 13px;
  color: #888;
}
.login-nudge a { color: #4a90e2; text-decoration: none; }
.login-nudge a:hover { text-decoration: underline; }

/* ── Fill Nav ─────────────────────────────────────────────────────────────── */
#fill-nav {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  /*flex-shrink: 0;*/
  height: 52px;
  background: #1a1a2e;
  padding: 0 20px;
  align-items: center;
  justify-content: space-between;
  z-index: 200;
}

#fill-nav.visible { display: flex; }

.logo {
  color: white;
  font-size: 18px;
  font-weight: bold;
  text-decoration: none;
}

#fill-nav .nav-center {
  flex: 1;
  text-align: center;
}

#fill-form-title {
  color: white;
  font-size: 15px;
  font-weight: bold;
}

#fill-nav .nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
  /*flex-shrink: 0;*/
}

.user-info {
  color: rgba(255,255,255,0.5);
  font-size: 12px;
}

.nav-btn {
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: none;
  background: rgba(255,255,255,0.1);
  color: white;
  text-decoration: none;
  transition: background 0.2s;
}
.nav-btn:hover { background: rgba(255,255,255,0.2); }
.nav-btn-primary { background: #4a90e2 !important; font-weight: 600; }
.nav-btn-primary:hover { background: #357abd !important; }

/* ── Fill Area ────────────────────────────────────────────────────────────── */
#fill-area {
  display: none;
  flex-direction: column;
  padding-top: 52px;   /* nav height */
  padding-bottom: 68px; /* action bar height */
  min-height: 100vh;
  overflow-y: auto;
  align-items: stretch;
}

#fill-area.visible { display: flex; }

/* ── Voice Panel ──────────────────────────────────────────────────────────── */
#voice-panel {
  width: 100%;
  background: #1a1a2e;
  border-bottom: 3px solid #4a90e2;
  padding: 14px 24px;
  flex-shrink: 0;
}

.voice-panel-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.voice-panel-icon { font-size: 28px; flex-shrink: 0; }

.voice-panel-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.voice-panel-text strong   { color: white; font-size: 14px; }
.voice-panel-text span     { color: rgba(255,255,255,0.6); font-size: 12px; }
#voice-panel-status        { color: #f0c040; font-size: 12px; min-height: 16px; }

/* Ring wrapper sits around the button */
.voice-btn-ring-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 148px;
  height: 44px;
  transition: width 0.3s ease, height 0.3s ease;
}

/* Expand wrap to fit the circle button + ring when recording */
.voice-btn-ring-wrap:has(#voice-panel-btn.recording) {
  width: 72px;
  height: 72px;
}

.record-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.record-ring.active { opacity: 1; }

.record-ring-track {
  fill: none;
  stroke: rgba(255,255,255,0.2);
  stroke-width: 4;
}

.record-ring-fill {
  fill: none;
  stroke: #27ae60;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 201.06;
  stroke-dashoffset: 201.06;
}

#voice-panel-btn {
  position: relative;
  z-index: 1;
  padding: 10px 20px;
  background: #4a90e2;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, border-radius 0.3s ease, width 0.3s ease, height 0.3s ease, padding 0.3s ease, font-size 0.2s;
}

#voice-panel-btn:hover { background: #357abd; }

#voice-panel-btn.recording {
  background: #e74c3c;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  padding: 0;
  font-size: 20px;
  animation: pulse 1s infinite;
}

#filler-canvas-wrap {
  display: flex;
  justify-content: center;
  padding: 30px 20px;
  width: 100%;
}

#filler-canvas {
  background: white;
  position: relative;
  box-shadow: 0 4px 24px rgba(0,0,0,0.12);
  flex-shrink: 0;
}

/* ── Field Elements ───────────────────────────────────────────────────────── */
.filler-field {
  position: absolute;
}

/* ── Per-field mic button ─────────────────────────────────────────────────── */
.field-mic-btn {
  position: absolute;
  right: -30px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #1a1a2e;
  color: white;
  border: none;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s, background 0.2s;
  z-index: 10;
}

/* Show on hover or focus-within */
.filler-field:hover .field-mic-btn,
.filler-field:focus-within .field-mic-btn {
  opacity: 1;
}

/* Always visible on touch devices */
@media (hover: none) {
  .field-mic-btn { opacity: 1; }
}

/* Recording state */
.field-mic-btn.recording {
  background: #e74c3c;
  opacity: 1;
  animation: pulse 1s infinite;
}

/* "Listening…" tooltip to the left of the mic button */
.field-mic-btn.recording::before {
  content: 'Listening…';
  position: absolute;
  right: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.75);
  color: white;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  white-space: nowrap;
  pointer-events: none;
}

.field-mic-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

.field-mic-btn.loading {
  opacity: 1;
  background: #4a90e2;
  cursor: wait;
}

.filler-label {
  position: absolute;
  top: -16px;
  left: 0;
  font-size: 11px;
  color: #4a90e2;
  font-weight: bold;
  white-space: nowrap;
  pointer-events: none;
}

.filler-field.type-textblock .filler-label {
  display: none;
}

.filler-field.type-textblock span {
  display: block;
  width: 100%;
  height: 100%;
  padding: 4px 6px;
}

/* Inputs */
.filler-input {
  width: 100%;
  height: 100%;
  padding: 0 8px;
  border-radius: 4px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  display: block;
}

.filler-input:focus {
  border-color: #4a90e2 !important;
  box-shadow: 0 0 0 2px rgba(74,144,226,0.2);
}

.filler-field.type-textarea .filler-input {
  padding: 8px;
  resize: none;
}

/* Checkbox */
.cb-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 100%;
  cursor: pointer;
}

.cb-wrap input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Signature */
.sig-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sig-canvas {
  border: 2px dashed #ccc;
  border-radius: 4px;
  cursor: crosshair;
  display: block;
  flex: 1;
  width: 100%;
}

.sig-canvas:hover { border-color: #4a90e2; }

.sig-clear-btn {
  align-self: flex-end;
  padding: 3px 10px;
  font-size: 11px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  color: #666;
  transition: all 0.15s;
}
.sig-clear-btn:hover { border-color: #e74c3c; color: #e74c3c; }

/* Date field wrapper + format hint */
.date-field-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  height: 100%;
}

.date-field-wrap .filler-input {
  flex: 1;
}

.date-format-hint {
  font-size: 10px;
  color: #aaa;
  letter-spacing: 0.02em;
}

/* AI-filled highlight flash */
.filler-input.ai-filled {
  animation: ai-flash 2.5s ease forwards;
}

@keyframes ai-flash {
  0%   { background-color: #fffbe6; box-shadow: 0 0 0 2px #f0c040; }
  80%  { background-color: #fffbe6; box-shadow: 0 0 0 2px #f0c040; }
  100% { background-color: inherit; box-shadow: none; }
}

/* ── Voice Button ─────────────────────────────────────────────────────────── */
#voice-btn {
  display: none;
  position: fixed;
  bottom: 76px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1a1a2e;
  color: white;
  font-size: 22px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  z-index: 300;
  transition: background 0.2s, transform 0.15s;
}

#voice-btn:hover { background: #4a90e2; transform: scale(1.08); }

#voice-btn.recording {
  background: #e74c3c;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,0.5); }
  50%       { box-shadow: 0 0 0 12px rgba(231,76,60,0); }
}

/* ── Action Bar ───────────────────────────────────────────────────────────── */
#action-bar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: white;
  border-top: 1px solid #e0e0e0;
  padding: 0 24px;
  align-items: center;
  justify-content: space-between;
  z-index: 200;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

#action-bar.visible { display: flex; }

#btn-error-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: white;
  border: 1px solid #4a90e2;
  color: #4a90e2;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
#btn-error-check:hover { background: #f0f6ff; }

.pro-badge {
  font-size: 10px;
  background: #4a90e2;
  color: white;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: bold;
}

/* ── Page navigation ──────────────────────────────────────────────────────── */
#page-nav {
  display: none;
  align-items: center;
  gap: 10px;
}

#page-indicator {
  font-size: 13px;
  color: #666;
  min-width: 90px;
  text-align: center;
}

#btn-prev-page,
#btn-next-page {
  padding: 8px 16px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

#btn-prev-page:hover,
#btn-next-page:hover { border-color: #4a90e2; color: #4a90e2; }

#btn-prev-page:disabled,
#btn-next-page:disabled { opacity: 0.35; cursor: default; }

#btn-submit {
  padding: 10px 28px;
  background: #27ae60;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}
#btn-submit:hover  { background: #1e8449; }
#btn-submit:disabled { background: #95a5a6; cursor: default; }

/* ── Issues Overlay ───────────────────────────────────────────────────────── */
#issues-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 400;
  justify-content: flex-end;
}

#issues-overlay.visible { display: flex; }

#issues-panel {
  width: 340px;
  max-width: 90vw;
  background: white;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.15);
}

#issues-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
}

.issues-close-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #999;
  line-height: 1;
}
.issues-close-btn:hover { color: #333; }

#issues-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.issues-ok {
  text-align: center;
  padding: 40px 20px;
  font-size: 15px;
  color: #27ae60;
}

.issue-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fafafa;
  border-left: 4px solid #ccc;
}

.issue-item.severity-error   { border-color: #e74c3c; background: #fff5f5; }
.issue-item.severity-warning { border-color: #f39c12; background: #fffaf0; }
.issue-item.severity-info    { border-color: #4a90e2; background: #f0f6ff; }

.issue-badge {
  font-size: 10px;
  font-weight: bold;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  height: fit-content;
  white-space: nowrap;
  flex-shrink: 0;
}

.severity-error   .issue-badge { background: #e74c3c; color: white; }
.severity-warning .issue-badge { background: #f39c12; color: white; }
.severity-info    .issue-badge { background: #4a90e2; color: white; }

.issue-body strong { font-size: 13px; display: block; margin-bottom: 4px; }
.issue-body p { font-size: 12px; color: #555; line-height: 1.5; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1a1a2e;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 9999;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
}

#toast.show    { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.error   { background: #e74c3c; }
#toast.success { background: #27ae60; }

/* ── Submission Receipt Overlay ───────────────────────────────────────────── */
#receipt-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 8000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#receipt-panel {
  background: white;
  border-radius: 14px;
  padding: 36px 32px 28px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
  text-align: center;
}

.receipt-icon { font-size: 48px; margin-bottom: 10px; }

#receipt-panel h2 {
  font-size: 22px;
  color: #1a1a2e;
  margin-bottom: 6px;
}

.receipt-sub {
  font-size: 13px;
  color: #888;
  margin-bottom: 24px;
  line-height: 1.5;
}

.receipt-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  text-align: left;
}

.receipt-label {
  font-size: 12px;
  color: #999;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  padding-top: 2px;
}

.receipt-value {
  font-size: 13px;
  color: #1a1a2e;
  text-align: right;
}

.receipt-value.mono { font-family: monospace; }

.receipt-hint {
  font-size: 12px;
  color: #888;
  margin: 20px 0 8px;
  text-align: left;
}

.receipt-link-row {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.receipt-link-row input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 11px;
  font-family: monospace;
  color: #555;
  background: #f8f9fa;
  outline: none;
}

.receipt-link-row button {
  padding: 8px 16px;
  background: #4a90e2;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.receipt-link-row button:hover { background: #357abd; }

.receipt-close-btn {
  width: 100%;
  padding: 12px;
  background: #f0f0f0;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  color: #555;
  cursor: pointer;
  transition: background 0.2s;
}
.receipt-close-btn:hover { background: #e0e0e0; }

/* ── Image fields in filler ──────────────────────────────────────────────── */
.filler-img-wrap {
  width:  100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.filler-img-static {
  width:  100%;
  height: 100%;
  display: block;
}

.filler-img-placeholder {
  font-size: 32px;
  color: #ddd;
  text-align: center;
}

/* ── Uploadable image zone ───────────────────────────────────────────────── */
.filler-img-upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width:  100%;
  height: 100%;
  border: 2px dashed #d0d5dd;
  border-radius: 6px;
  background: #fafbfc;
  padding: 12px;
}

.filler-img-upload-btn {
  padding: 10px 18px;
  background: #4a90e2;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.filler-img-upload-btn:hover    { background: #357abd; }
.filler-img-upload-btn:disabled { opacity: 0.5; cursor: default; }

.filler-img-status {
  font-size: 12px;
  color: #e74c3c;
  text-align: center;
}

/* ── Image preview with resize handle ───────────────────────────────────── */
.filler-img-preview {
  position: relative;
  display: inline-block;
  min-width: 80px;
  min-height: 60px;
}

.filler-img-preview-img {
  display: block;
  width:  100%;
  height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.filler-img-resize-handle {
  position: absolute;
  bottom: 0;
  right:  0;
  width:  18px;
  height: 18px;
  background: #4a90e2;
  border-radius: 2px 0 4px 0;
  cursor: se-resize;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.filler-img-resize-handle::after {
  content: '';
  position: absolute;
  inset: 3px 3px 4px 4px;
  border-right: 2px solid white;
  border-bottom: 2px solid white;
}
.filler-img-resize-handle:hover { opacity: 1; }

.filler-img-change-btn {
  position: absolute;
  top:  6px;
  right: 6px;
  padding: 3px 8px;
  font-size: 11px;
  background: rgba(0,0,0,0.55);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.filler-img-preview:hover .filler-img-change-btn { opacity: 1; }

/* ── Print / Save as PDF ─────────────────────────────────────────────────── */
#print-all-pages { display: none; }

@media print {
  /* Hide everything except the print container */
  body > *:not(#print-all-pages) { display: none !important; }
  #print-all-pages                { display: block !important; }

  body        { background: white; margin: 0; padding: 0; }
  @page       { margin: 0.5in; size: auto; }

  /* Form title above the first page */
  .print-form-title {
    font-family: Arial, sans-serif;
    font-size: 18px;
    font-weight: bold;
    color: #1a1a2e;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #1a1a2e;
  }

  /* Each form page */
  .print-page {
    position: relative;
    break-inside: avoid;
    page-break-inside: avoid;
    page-break-after: always;
    box-shadow: none;
    margin: 0 auto 0;
  }
  .print-page:last-child { page-break-after: auto; }
}
