:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #f9fbff;
  --text: #172033;
  --muted: #607089;
  --line: #dce5f2;
  --primary: #1668dc;
  --primary-dark: #0f4fb3;
  --success: #168a45;
  --success-bg: #e8f7ef;
  --danger: #c92a2a;
  --danger-bg: #fff1f1;
  --warning: #9b6200;
  --warning-bg: #fff6df;
  --shadow: 0 10px 30px rgba(21, 43, 77, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

a {
  color: inherit;
}

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

button {
  border: 0;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.brand strong {
  font-size: 20px;
  letter-spacing: 0;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.container {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

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

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2,
.section-title {
  margin: 0;
  font-size: 20px;
}

.panel-header p,
.section-subtitle {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.panel-body {
  padding: 22px;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.75fr);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  color: #2d3b52;
  font-weight: 700;
  font-size: 14px;
}

.field input,
.field textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
  border: 1px solid #cfd9e8;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 104, 220, 0.12);
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 9px 14px;
  color: #fff;
  background: var(--primary);
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.16s ease, box-shadow 0.16s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--primary-dark);
  box-shadow: 0 8px 18px rgba(22, 104, 220, 0.18);
}

.btn:active {
  transform: translateY(1px);
}

.btn.secondary {
  color: #1b365d;
  background: #eef4ff;
}

.btn.secondary:hover {
  background: #dfeaff;
  box-shadow: none;
}

.btn.success {
  background: var(--success);
}

.btn.success:hover {
  background: #0e6f36;
}

.btn.danger {
  background: var(--danger);
}

.btn.danger:hover {
  background: #a81f1f;
}

.btn.ghost {
  color: #34445e;
  background: transparent;
  border: 1px solid #cfd9e8;
}

.btn.ghost:hover {
  background: #f5f8fc;
  box-shadow: none;
}

.btn[disabled],
.btn.disabled {
  opacity: 0.58;
  cursor: not-allowed;
  pointer-events: none;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 12px 11px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: #35445d;
  font-size: 13px;
  background: #f1f5fb;
  white-space: nowrap;
}

tr:nth-child(even) td {
  background: #fbfdff;
}

.status {
  display: inline-flex;
  align-items: center;
  min-width: 58px;
  justify-content: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status.signed {
  color: var(--success);
  background: var(--success-bg);
}

.status.pending {
  color: var(--danger);
  background: var(--danger-bg);
}

.status.warn {
  color: var(--warning);
  background: var(--warning-bg);
}

.progress-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 160px;
}

.progress-track {
  overflow: hidden;
  flex: 1;
  height: 8px;
  background: #e7edf6;
  border-radius: 999px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: inherit;
}

.muted {
  color: var(--muted);
}

.empty {
  padding: 26px;
  color: var(--muted);
  text-align: center;
}

.login-overlay,
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(9, 18, 31, 0.54);
}

.login-overlay.show,
.modal-overlay.show {
  display: flex;
}

.login-box,
.signature-modal {
  width: min(520px, 100%);
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.26);
}

.login-box {
  padding: 24px;
}

.login-box h2 {
  margin: 0 0 8px;
}

.login-box p {
  margin: 0 0 18px;
  color: var(--muted);
}

.notice {
  display: none;
  margin: 0 0 16px;
  padding: 11px 12px;
  border-radius: 6px;
  color: var(--danger);
  background: var(--danger-bg);
}

.notice.show {
  display: block;
}

.item-editor {
  display: grid;
  gap: 10px;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mode-switch label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid #cfd9e8;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.mode-switch input {
  width: 16px;
  height: 16px;
}

.mode-switch label:has(input:checked) {
  color: var(--primary);
  border-color: var(--primary);
  background: #eef4ff;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px 90px 42px;
  gap: 8px;
  align-items: center;
}

.item-row input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #cfd9e8;
  border-radius: 6px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  color: #53657f;
  background: #f2f6fb;
  border-radius: 6px;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--danger);
  background: #ffecec;
}

.project-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-box {
  padding: 14px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-box span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.summary-box strong {
  display: block;
  margin-top: 5px;
  font-size: 22px;
}

.sign-pad-mini {
  width: 150px;
  height: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px dashed #b8c5d8;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}

.sign-pad-mini.readonly {
  cursor: default;
}

.sign-pad-mini img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.sign-pad-mini span {
  color: #7a8799;
  font-size: 13px;
}

.signature-thumb {
  width: 150px;
  height: 58px;
  object-fit: contain;
  background: #fff;
  border: 1px solid #d5dfec;
  border-radius: 6px;
}

.signature-modal {
  width: min(900px, calc(100vw - 28px));
  padding: 18px;
}

.signature-modal header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.signature-modal h3 {
  margin: 0;
}

.signature-area {
  position: relative;
  height: min(56vh, 420px);
  min-height: 260px;
  background: #fff;
  border: 2px dashed #b4c2d4;
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
}

.signature-area canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.signature-watermark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(84, 100, 125, 0.18);
  font-size: clamp(32px, 9vw, 86px);
  font-weight: 800;
  pointer-events: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.signer-input {
  width: min(320px, 100%);
}

.footer-tip {
  margin-top: 18px;
  color: var(--muted);
  text-align: center;
}

.export-page {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1120px;
  padding: 32px;
  color: #111827;
  background: #fff;
  font-family: "Microsoft YaHei", sans-serif;
}

.export-page h1 {
  margin: 0 0 18px;
  text-align: center;
  font-size: 28px;
}

.export-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
  font-size: 15px;
}

.export-page table {
  font-size: 14px;
}

.export-page th,
.export-page td {
  border: 1px solid #b9c5d5;
}

.export-signature-cell {
  height: 76px;
  padding: 4px 6px;
  text-align: center;
  vertical-align: middle;
}

.export-signature-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 178px;
  height: 66px;
  margin: 0 auto;
  overflow: hidden;
}

.export-signature-box img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: none;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  color: #fff;
  background: #14213d;
  border-radius: 8px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.2);
}

.toast.show {
  display: block;
}

@media (max-width: 900px) {
  .grid.two,
  .form-grid,
  .project-summary {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

@media (max-width: 640px) {
  .container {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .panel-header,
  .panel-body {
    padding: 16px;
  }

  .brand strong {
    font-size: 18px;
  }

  .item-row {
    grid-template-columns: 1fr 70px 70px 38px;
  }

  .mode-switch {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 10px 8px;
    font-size: 13px;
  }

  .btn {
    min-height: 36px;
    padding: 8px 11px;
  }

  .signature-modal {
    padding: 14px;
  }

  .signature-area {
    height: 58vh;
    min-height: 300px;
  }
}
