:root {
  --ink: #10242b;
  --muted: #617179;
  --line: #d5e0e2;
  --panel: #ffffff;
  --page: #eff4f5;
  --brand: #075b63;
  --brand-dark: #043f45;
  --accent: #d87436;
  --success: #267348;
  --danger: #b42318;
  --shadow: 0 14px 42px rgba(16, 36, 43, 0.07);
}

* {
  box-sizing: border-box;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(135deg, #f6f9f9 0%, var(--page) 62%, #e8f0f1 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid rgba(213, 224, 226, 0.85);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
}

.app-header.compact {
  padding-block: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 3vw, 2.5rem);
  line-height: 1.05;
}

h2 {
  margin-bottom: 0;
  font-size: 1.08rem;
}

.status-pill {
  max-width: 46vw;
  overflow: hidden;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #f8fafb;
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(290px, 0.76fr) minmax(0, 1.24fr);
  grid-template-areas:
    "upload documents"
    "send fields";
  gap: 18px;
  padding: 22px clamp(18px, 4vw, 48px) 40px;
}

.upload-panel { grid-area: upload; }
.documents-panel { grid-area: documents; }
.field-panel { grid-area: fields; }
.send-panel { grid-area: send; }

.signin-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
}

.signin-shell {
  width: min(440px, 100%);
}

.signin-panel h1 {
  font-size: 2rem;
}

.signin-note {
  display: grid;
  gap: 5px;
  margin: 0 18px 18px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  background: #f9fbfc;
  font-size: 0.9rem;
}

.signin-note strong {
  color: var(--ink);
}

.sign-workspace {
  display: grid;
  grid-template-columns: minmax(360px, 1.4fr) minmax(320px, 0.8fr);
  gap: 18px;
  padding: 22px clamp(18px, 4vw, 48px) 40px;
}

.admin-workspace {
  display: grid;
  gap: 18px;
  padding: 22px clamp(18px, 4vw, 48px) 40px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.form-grid {
  display: grid;
  gap: 14px;
  padding: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 11px 12px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(9, 107, 114, 0.14);
}

.file-drop {
  min-height: 180px;
  place-items: center;
  align-content: center;
  border: 1px dashed #aab6c2;
  border-radius: 12px;
  padding: 20px;
  color: var(--ink);
  background: #f9fbfc;
  text-align: center;
  cursor: pointer;
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.file-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--brand);
  font-size: 1.7rem;
  line-height: 1;
}

.file-drop small {
  color: var(--muted);
  font-weight: 500;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.primary-button {
  padding: 12px 15px;
  color: #ffffff;
  background: var(--brand);
}

.primary-button:hover {
  background: var(--brand-dark);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #ffffff;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #ffffff;
  font-size: 1.2rem;
}

.documents-list {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.document-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fbfcfd;
}

.document-item h3 {
  margin: 0 0 5px;
  font-size: 1rem;
}

.document-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.badge {
  justify-self: start;
  padding: 5px 8px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.badge.signed {
  background: var(--success);
}

.badge.draft {
  background: #64748b;
}

.document-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.link-box {
  display: grid;
  gap: 10px;
  margin: 0 18px 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfc;
}

.link-box span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.multi-links {
  display: grid;
  gap: 8px;
}

.queue-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
}

.queue-row span {
  color: var(--muted);
  font-weight: 600;
}

.preview-panel iframe {
  display: block;
  width: 100%;
  height: min(72vh, 820px);
  border: 0;
  background: #eef2f5;
}

.sign-preview {
  position: relative;
  min-height: min(72vh, 820px);
}

.sign-preview iframe {
  pointer-events: auto;
}

.signer-marker {
  pointer-events: none;
  background: rgba(210, 111, 49, 0.2);
  border-color: var(--accent);
  color: #8a3f13;
}

.field-preview {
  position: relative;
  min-height: 520px;
  overflow: hidden;
  background: #eef2f5;
}

.field-toolbar {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(110px, 0.8fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.field-preview iframe {
  display: block;
  width: 100%;
  height: 520px;
  border: 0;
  pointer-events: none;
}

.field-layer {
  position: absolute;
  inset: 0;
}

.signature-field {
  position: absolute;
  display: grid;
  min-width: 90px;
  min-height: 42px;
  place-items: center;
  border: 2px solid var(--brand);
  border-radius: 6px;
  color: var(--brand-dark);
  background: rgba(9, 107, 114, 0.16);
  font-size: 0.9rem;
  font-weight: 800;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.signature-field.active {
  box-shadow: 0 0 0 3px rgba(210, 111, 49, 0.25);
}

.signature-field small {
  display: block;
  color: inherit;
  font-size: 0.68rem;
  font-weight: 700;
}

.signature-field:active {
  cursor: grabbing;
}

.signature-box {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.signing-fields {
  display: grid;
  gap: 12px;
}

canvas {
  display: block;
  width: 100%;
  height: 220px;
  cursor: crosshair;
}

.legal-note,
.scan-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.scan-dialog {
  width: min(860px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 28px 80px rgba(4, 30, 34, 0.28);
}

.scan-dialog::backdrop {
  background: rgba(6, 25, 30, 0.72);
  backdrop-filter: blur(5px);
}

.scan-shell,
.scan-body {
  display: grid;
}

.scan-body {
  gap: 16px;
  padding: 18px;
}

#scanVideo {
  width: 100%;
  max-height: 52vh;
  border-radius: 12px;
  background: #0b171b;
  object-fit: contain;
}

.scan-pages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
}

.scan-pages > p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
}

.scan-page {
  position: relative;
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.scan-page img {
  width: 100%;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
}

.scan-page button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgba(16, 36, 43, 0.82);
  cursor: pointer;
}

.check-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  color: var(--ink);
  font-weight: 600;
}

.check-row input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
  padding: 18px;
}

.admin-grid div,
.audit-item {
  display: grid;
  gap: 5px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.admin-grid .wide {
  grid-column: span 2;
}

.admin-grid strong {
  overflow-wrap: anywhere;
  font-size: 1.1rem;
}

.admin-grid span,
.audit-item span,
.audit-item small,
.audit-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.audit-list {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.empty-state {
  padding: 24px 18px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .workspace,
  .sign-workspace {
    grid-template-columns: 1fr;
  }

  .workspace {
    grid-template-areas: "upload" "documents" "fields" "send";
  }

  .admin-grid {
    grid-template-columns: 1fr 1fr;
  }

  .field-toolbar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .status-pill {
    max-width: 100%;
  }

  .document-item {
    grid-template-columns: 1fr;
  }

  .document-actions {
    flex-wrap: wrap;
  }

  .admin-grid,
  .admin-grid .wide {
    grid-template-columns: 1fr;
    grid-column: auto;
  }

  .field-toolbar {
    grid-template-columns: 1fr;
  }
}
