/* ========== Reset & Base ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --success: #52c41a;
  --danger: #ff4d4f;
  --bg: #f0f0f0;
  --card-bg: #ffffff;
  --text: #333333;
  --text-secondary: #666666;
  --border: #e8e8e8;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ========== Layout ========== */
.container {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 20px 24px 40px;
}

.header {
  padding: 30px 0 20px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.header-left h1 {
  font-size: 25px;
  color: var(--primary);
  margin-bottom: 6px;
}

.header-left .subtitle {
  font-size: 15px;
  color: var(--text-secondary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* ========== Card ========== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .icon {
  width: 20px;
  height: 20px;
}

.card-hint {
  margin-left: auto;
  font-size: 13px;
  font-weight: 400;
  color: #1677ff;
  background: #e6f4ff;
  padding: 2px 10px;
  border-radius: 10px;
}

/* ========== Form ========== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group label .required {
  color: var(--danger);
  margin-left: 2px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  background: #fafafa;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.1);
  background: #fff;
}

.form-group textarea {
  min-height: 120px;
  resize: vertical;
}

/* ========== 合同内容查看器 ========== */
#contractCard {
  padding: 0 !important;
  overflow: hidden;
}

.contract-viewer-wrapper {
  background: #e8e8e8;
  min-height: 60vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 16px;
}

.contract-viewer-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  width: 100%;
}

.contract-page {
  width: 100%;
  background: #fff;
  box-shadow: 0 2px 16px rgba(0,0,0,0.12);
  border-radius: 2px;
  padding: 64px 72px;
  font-family: "SimSun","STSong","Noto Serif CJK SC","Source Han Serif SC","Microsoft YaHei","微软雅黑",serif;
  font-size: 17px;
  line-height: 2.2;
  color: #1a1a1a;
  white-space: pre-wrap;
  word-break: break-all;
}

.contract-page h1 {
  text-align: center;
  font-size: 25px;
  font-weight: bold;
  margin: 0 0 32px 0;
  font-family: "SimHei","STHeiti","Noto Sans CJK SC","Microsoft YaHei","微软雅黑",sans-serif;
  letter-spacing: 3px;
  line-height: 1.6;
}

.contract-page .section-title {
  font-weight: bold;
  font-size: 18px;
  margin: 20px 0 6px;
  font-family: "SimHei","STHeiti","Microsoft YaHei","微软雅黑",sans-serif;
}

.contract-page .item-label {
  font-weight: bold;
}

.contract-page .article-title {
  font-weight: bold;
  font-size: 18px;
  margin: 22px 0 8px;
  font-family: "SimHei","STHeiti","Microsoft YaHei","微软雅黑",sans-serif;
}

.contract-page .signature-line {
  font-weight: bold;
}

.contract-page .sub-item {
  text-indent: 2em;
}

.contract-page .sub-item strong,
.contract-page strong {
  font-weight: bold;
}

/* ========== 行内嵌入式输入 ========== */
.inline-field {
  display: inline-block;
  vertical-align: baseline;
}

/* 行内文本输入框 - 下划线样式融入文档 */
.inline-input {
  border: none;
  border-bottom: 1.5px dashed #bbb;
  background: transparent;
  font: inherit;
  color: #1677ff;
  outline: none;
  padding: 0 4px;
  min-width: 60px;
  border-radius: 0;
  transition: border-color 0.2s;
  text-align: center;
}

.inline-input:focus {
  border-bottom: 2px solid #1677ff;
  background: rgba(22,119,255,0.03);
}

.inline-input::placeholder {
  color: #ff4d4f;
  font-size: 0.9em;
}

.inline-date::placeholder {
  color: #ff4d4f;
}

.inline-input.name-input { min-width: 80px; }
.inline-input.id-input { min-width: 160px; letter-spacing: 1px; }
.inline-input.phone-input { min-width: 120px; }

/* 行内只读值 (已签署后) */
.inline-value {
  display: inline;
  border-bottom: 1.5px solid #bbb;
  padding: 0 4px;
  color: #333;
}

/* 行内日期选择器 */
.inline-date {
  border: none;
  border-bottom: 1.5px dashed #bbb;
  background: transparent;
  font: inherit;
  color: #1677ff;
  outline: none;
  padding: 0 4px;
  min-width: 130px;
  border-radius: 0;
  transition: border-color 0.2s;
}

.inline-date:focus {
  border-bottom: 2px solid #1677ff;
}

/* ========== 两栏签名区域（桌面并排 / 手机上下堆叠） ========== */
.sign-row {
  display: flex;
  gap: 48px;
  margin-top: 28px;
  padding: 20px 0;
  border-top: 1px dashed #d0d0d0;
}

.sign-col {
  flex: 1;
  min-width: 0;
}

/* 签字/盖章 行 */
.sign-item-row {
  font-size: 17px;
  font-weight: bold;
  line-height: 1.8;
  min-height: 50px;           /* 固定高度，签前签后甲乙方对齐 */
  display: flex;
  align-items: center;
  font-family: "SimHei","STHeiti","Microsoft YaHei","微软雅黑",sans-serif;
}

/* 签字行区域（无虚线） */
.sign-blank {
  display: inline-block;
  min-width: 120px;
  vertical-align: middle;
}

/* 乙方签字行可点击 */
.sig-clickable {
  cursor: pointer;
  color: #1a1a1a;
}
.sig-clickable:hover .sign-blank {
  color: #1677ff;
}

/* 签名提示文字 - 红色，位于虚线上方 */
.sig-hint-inline {
  color: #ff4d4f;
  font-size: 0.9em;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  vertical-align: top;
  line-height: normal;
}

/* 日期行 */
.sign-date-row {
  font-size: 16px;
  line-height: 2;
  color: #555;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.date-label {
  font-weight: 500;
}

.date-value {
  display: inline-flex;
  align-items: center;
}

.date-value .inline-date {
  border: none !important;
  border-radius: 0 !important;
  padding: 0 4px !important;
  min-width: 130px;
  background: transparent;
  cursor: pointer;
  /* 隐藏日历图标 */
  -webkit-appearance: none;
  appearance: none;
}
/* Safari/Chrome 隐藏 date 日历按钮 */
.date-value .inline-date::-webkit-calendar-picker-indicator {
  display: none;
}

.date-value .inline-date:focus {
  outline: none;
}

/* ========== 签名触发器 + 预览 ========== */
.sig-wrap {
  margin-top: 6px;
}

.sig-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 90px;
  border: 2px dashed #1677ff;
  border-radius: 8px;
  background: #f0f7ff;
  color: #1677ff;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  letter-spacing: 1px;
}

.sig-trigger:hover, .sig-trigger:active {
  background: #e6f4ff;
  border-color: #4096ff;
}

.sig-preview {
  display: block;
  width: 100%;
  max-height: 100px;
  object-fit: contain;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  background: #fff;
}

/* 行内签名预览（替换placeholder） */
.sig-inline-preview {
  display: inline-block;
  max-height: 88px;
  max-width: 300px;
  object-fit: contain;
  vertical-align: middle;
  cursor: pointer;
  position: relative;
  z-index: 1;
}

.sig-re-sign {
  font-size: 13px;
  color: #1677ff;
  text-align: center;
  cursor: pointer;
  margin-top: 4px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.sig-re-sign:hover { text-decoration: underline; }

/* ========== 签名弹窗 ========== */
.sig-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.55);
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
.sig-modal-overlay.show { display: flex; }

.sig-modal-body {
  width: 680px;
  max-width: 92vw;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 12px 50px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* 关闭按钮 — 弹窗右上角 */
.sig-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  background: rgba(255,255,255,0.9);
  border: 1px solid #ddd;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 19px;
  color: #666;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.sig-modal-close:hover { color: #333; background: #fff; }

/* 左侧按钮区 — 桌面：底部横向 */
.sig-modal-left {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px 20px 20px;
  flex-shrink: 0;
  order: 2;
  background: #fff;
  border-top: 1px solid #eee;
}

/* 右侧文字区 — 桌面隐藏 */
.sig-modal-right {
  display: none;
}

.sig-modal-label {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 19px;
  font-weight: 600;
  color: #888;
  letter-spacing: 4px;
}

.sig-modal-canvas-wrap {
  order: 1;
  height: 400px;
  padding: 8px;
  background: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
}

.sig-modal-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 6px;
  cursor: crosshair;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  border: 1px solid #e8e8e8;
}

.sig-btn-clear {
  padding: 10px 24px;
  font-size: 16px;
  min-width: 80px;
}

.sig-btn-confirm {
  padding: 10px 24px;
  font-size: 16px;
  min-width: 80px;
}

/* ========== 手机：签名弹窗横屏全屏 + 签名区堆叠 ========== */
@media (max-width: 768px) {
  /* 弹窗横屏全屏 */
  .sig-modal-body {
    width: 100vw;
    height: 80vh;
    height: 80dvh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    flex-direction: row;         /* 手机端横向三栏 */
  }

  .sig-modal-left {
    flex-direction: column;      /* 按钮竖向堆叠 */
    order: 0;                    /* 恢复左侧位置 */
    padding: 16px 10px;
    gap: 46px;
    justify-content: flex-end;
    align-items: center;
    background: #f8f8f8;
    border-right: 1px solid #eee;
    border-top: none;
  }


  .sig-modal-canvas-wrap {
    order: 0;
    height: auto;
    flex: 1;
    max-width: 72vw;
    margin: 0 auto;
    min-height: 0;
    touch-action: none;
  }


  .sig-modal-close {
    margin-top: 30px;
    position: absolute;
    top: 16px; left: 16px;
    right: auto;
    width: auto; height: auto;
    border-radius: 6px;
    background: #e53e3e;
    color: #fff;
    border: none;
    padding: 12px 20px;
    font-size: 0;              /* 隐藏 ✕ 文字 */
    font-weight: 500;
    min-width: unset;
    white-space: nowrap;
    transform: rotate(90deg);
    cursor: pointer;
    z-index: 10;
  }
  .sig-modal-close::after {
    content: '取消';
    font-size: 17px;
  }

  .sig-btn-clear, .sig-btn-confirm {
    margin-bottom: 30px;
    padding: 6px 10px;
    font-size: 15px;
    min-width: unset;
    height: auto;
    white-space: nowrap;
    transform: rotate(90deg);
  }

  /* 签名区上下堆叠 */
  .sign-row {
    flex-direction: column;
    gap: 24px;
    padding: 16px 0;
  }

  .sign-col-party-a { padding-bottom: 16px; border-bottom: 1px dotted #e0e0e0; }

  .sign-item-row { font-size: 17px; min-height: 44px; }
  .sign-blank { min-width: 80px; }
  .sig-inline-preview { min-height: 150px; min-width: 150px; max-height: 200px; max-width: 200px; }

  /* 手机端输入框加宽，避免内容被裁 */
  .inline-input.id-input { min-width: 230px; }
  .inline-input.phone-input { min-width: 140px; }
  .sign-date-row { font-size: 16px; }
  .sig-trigger { height: 76px; font-size: 16px; }
}

/* ========== PDF 工具栏(下载用) ========== */
.pdf-toolbar {
  display: flex;
  margin-left: auto;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.toolbar-btn {
  background: #fff;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
  line-height: 1.4;
}

.toolbar-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ========== Signature Pad ========== */
.signature-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.signature-pad {
  width: 100%;
  height: 180px;
  cursor: crosshair;
  touch-action: none;
}

.signature-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #fafafa;
  border-top: 1px solid var(--border);
}

.signature-actions .hint {
  font-size: 13px;
  color: #999;
}

.clear-btn {
  font-size: 14px;
  color: var(--danger);
  background: none;
  border: 1px solid var(--danger);
  border-radius: 4px;
  padding: 4px 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.clear-btn:hover {
  background: #fff1f0;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: #73d13d;
}

.btn-outline {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn-outline:hover:not(:disabled) {
  background: #e6f4ff;
}

.btn-group {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.btn-group .btn {
  flex: 1;
}

.btn-sm {
  width: auto !important;
  padding: 6px 16px !important;
  font-size: 14px !important;
  border-radius: 6px !important;
}

/* ========== Status Badge ========== */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
}

.badge-pending {
  background: #fff7e6;
  color: #fa8c16;
}

.badge-signed {
  background: #f6ffed;
  color: #52c41a;
}

/* ========== Toast / Message ========== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 15px;
  color: #fff;
  z-index: 1000;
  animation: slideDown 0.3s ease;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }

@keyframes slideDown {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ========== Share Link ========== */
.share-box {
  background: #f0f5ff;
  border: 1px dashed var(--primary);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
}

.share-box .share-label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.share-box .share-url {
  display: flex;
  gap: 8px;
}

.share-box .share-url input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}

.share-box .copy-btn {
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

/* ========== Loading ========== */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.8);
  z-index: 999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.loading-overlay.show { display: flex; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Completed State ========== */
.success-icon {
  text-align: center;
  font-size: 49px;
  margin: 16px 0;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .container {
    padding: 12px 8px 24px;
  }
  .card {
    padding: 16px 10px;
  }
  .contract-page {
    padding: 32px 24px;
    font-size: 17px;
  }
  .contract-page h1 {
    font-size: 24px;
    margin-bottom: 24px;
  }
  .contract-viewer-wrapper {
    padding: 12px 8px;
    min-height: 40vh;
  }
  .btn-group {
    flex-direction: column;
  }
}

@media (max-width: 400px) {
  .container { padding: 8px 4px 20px; }
  .card { padding: 12px 8px; }
  .contract-page { padding: 20px 16px; }
}
