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

:root {
  --red: #8B0000;
  --red-light: #a80000;
  --black: #111111;
  --dark: #1a1a1a;
  --gray: #f5f5f5;
  --border: #e0e0e0;
  --text: #333;
  --white: #ffffff;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--gray);
  color: var(--text);
  min-height: 100vh;
}

/* ── HEADER ── */
header {
  background: var(--black);
  color: var(--white);
  padding: 0 32px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

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

.brand-icon {
  width: 32px;
  height: 32px;
  background: var(--red);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand-name span {
  color: var(--red);
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
}

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

.btn-dark {
  background: var(--black);
  color: var(--white);
}
.btn-dark:hover { background: #2a2a2a; }

.btn-outline {
  background: transparent;
  color: var(--red);
  border: 1.5px solid var(--red);
}
.btn-outline:hover { background: var(--red); color: var(--white); }

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

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

/* ── MAIN LAYOUT ── */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ── LOGIN PAGE ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--black);
}

.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 48px 40px;
  width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  text-align: center;
}

.login-logo {
  width: 60px;
  height: 60px;
  background: var(--red);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto 20px;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--black);
  margin-bottom: 6px;
}

.login-card p {
  font-size: 13px;
  color: #777;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 16px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--dark);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: border 0.15s;
}

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

.error-msg {
  color: var(--red);
  font-size: 13px;
  margin-top: 8px;
}

/* ── CARDS ── */
.card {
  background: var(--white);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  overflow: hidden;
  margin-bottom: 24px;
}

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

.card-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--dark);
}

.card-body {
  padding: 24px;
}

/* ── UPLOAD ZONE ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--red);
  background: #fff5f5;
}

.upload-zone input[type=file] { display: none; }
.upload-zone .upload-icon { font-size: 36px; margin-bottom: 8px; }
.upload-zone p { font-size: 14px; color: #666; }
.upload-zone strong { color: var(--red); }

/* ── TABLE ── */
.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.doc-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
  border-bottom: 1px solid var(--border);
}

.doc-table td {
  padding: 14px 16px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}

.doc-table tr:last-child td { border-bottom: none; }
.doc-table tr:hover td { background: #fafafa; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-pending { background: #fff3cd; color: #856404; }
.badge-signed { background: #d1f7e0; color: #166534; }

/* ── PDF EDITOR ── */
.pdf-editor {
  display: none;
}

.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--black);
  border-radius: 8px 8px 0 0;
  flex-wrap: wrap;
}

.pdf-toolbar span {
  color: var(--white);
  font-size: 13px;
}

.pdf-canvas-wrap {
  position: relative;
  background: #e8e8e8;
  border: 1px solid var(--border);
  overflow: auto;
  max-height: 600px;
}

#pdf-canvas {
  display: block;
  cursor: crosshair;
}

#field-overlays {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
}

#field-overlays > div {
  pointer-events: all;
}

.sig-field-overlay {
  position: absolute;
  border: 2px solid var(--red);
  background: rgba(139,0,0,0.12);
  cursor: move;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--red);
  user-select: none;
}

.sig-field-overlay.date-field {
  border-color: #1a56db;
  background: rgba(26,86,219,0.10);
  color: #1a56db;
}

.field-type-btn { opacity: 0.55; }
.field-type-btn.active-tool { opacity: 1; box-shadow: 0 0 0 2px white, 0 0 0 4px currentColor; }

.sig-field-overlay .remove-field {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 16px;
  height: 16px;
  background: var(--red);
  color: white;
  border-radius: 50%;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── LINK MODAL ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--white);
  border-radius: 12px;
  padding: 32px;
  width: 520px;
  max-width: 95vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--dark);
}

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

.link-box input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fafafa;
}

/* ── PAGE NAV ── */
.page-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
}

.page-nav button {
  background: #333;
  color: white;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.page-nav button:hover { background: var(--red); }
.page-nav span { font-size: 13px; }

/* ── SIGN PAGE ── */
.sign-page {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 16px;
}

.sign-header {
  text-align: center;
  margin-bottom: 28px;
}

.sign-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--black);
  margin-bottom: 6px;
}

.sign-header p { color: #666; font-size: 14px; }

.sign-pdf-wrap {
  position: relative;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  background: #fff;
}

#sign-field-markers {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
}

#sign-field-markers .sign-field-marker {
  pointer-events: all;
}

#sign-canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: -webkit-optimize-contrast;
}

.sign-field-marker {
  position: absolute;
  border: 2px dashed #8B0000;
  background: rgba(139,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #8B0000;
  cursor: move;
  user-select: none;
  pointer-events: all;
  z-index: 10;
}

.sign-form-card {
  background: var(--white);
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  margin-bottom: 24px;
}

.sign-form-card h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--dark);
}

.sig-canvas-wrap {
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  margin-bottom: 12px;
}

#sig-canvas {
  display: block;
  cursor: crosshair;
  touch-action: none;
  background: white;
}

.sig-canvas-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 14px;
  color: #bbb;
  pointer-events: none;
}

.consent-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 16px;
  margin-bottom: 24px;
}

.consent-row input[type=checkbox] {
  margin-top: 2px;
  width: 16px;
  height: 16px;
  accent-color: var(--red);
}

.consent-row label {
  font-size: 13px;
  color: #555;
  line-height: 1.5;
}

.success-screen {
  text-align: center;
  padding: 60px 20px;
  display: none;
}

.success-icon {
  width: 70px;
  height: 70px;
  background: #d1f7e0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin: 0 auto 20px;
}

.success-screen h2 {
  font-size: 22px;
  font-weight: 700;
  color: #166534;
  margin-bottom: 8px;
}

.success-screen p { color: #666; font-size: 14px; }

.page-nav-sign {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
  position: relative;
  z-index: 20;
}

.page-nav-sign button {
  background: var(--black);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  position: relative;
  z-index: 20;
}
.page-nav-sign button:hover { background: var(--red); }

@media (max-width: 600px) {
  .main { padding: 16px; }
  .card-body { padding: 16px; }
}
