:root {
  --bg: #f4f6f1;
  --ink: #171b16;
  --muted: #697166;
  --panel: #ffffff;
  --line: #d9dfd4;
  --brand: #126b5b;
  --brand-2: #1d8a73;
  --danger: #b54b31;
  --shadow: 0 18px 50px rgba(32, 43, 34, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}

.sidebar {
  background: #172019;
  color: white;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e8f3da;
  color: var(--brand);
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.note {
  color: #c2cbbf;
  font-size: 12px;
  line-height: 1.55;
}

.nav a {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
}

.note {
  margin-top: auto;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.user-box {
  display: grid;
  gap: 5px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.user-box strong,
.user-box span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-box span {
  color: #c2cbbf;
  font-size: 12px;
}

.user-box button {
  min-height: 30px;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  cursor: pointer;
}

.main {
  min-width: 0;
  padding: 24px;
}

.auth-wrap {
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
}

.auth-panel {
  width: min(460px, 100%);
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 17px;
  margin-bottom: 14px;
}

p {
  margin: 8px 0 0;
}

.page-head p,
.hint,
small {
  color: var(--muted);
  font-size: 13px;
}

.role-chip {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin-bottom: 8px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.role-a {
  background: #e4f3ee;
  color: #0e6758;
}

.role-b {
  background: #fff1d6;
  color: #835500;
}

.role-note {
  margin: -4px 0 12px;
  padding: 10px 11px;
  border: 1px solid #edd392;
  border-radius: 8px;
  background: #fff9e9;
  color: #765200;
}

.signature-box {
  display: grid;
  gap: 9px;
  margin: 12px 0;
}

.sender-signature-box {
  display: grid;
  gap: 10px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid #d7c072;
  border-radius: 8px;
  background: #fffbed;
}

.sender-signature-box.compact {
  padding: 10px;
}

.signature-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.signature-head span {
  color: #3d453b;
  font-size: 13px;
  font-weight: 800;
}

#signatureCanvas {
  width: 100%;
  height: 170px;
  display: block;
  border: 1px solid #bfc7ba;
  border-radius: 8px;
  background:
    linear-gradient(to bottom, transparent calc(100% - 38px), rgba(18, 107, 91, 0.13) calc(100% - 37px), transparent calc(100% - 36px)),
    #fffef8;
  touch-action: none;
  cursor: crosshair;
}

.sender-signature-preview {
  max-width: 100%;
  max-height: 96px;
  object-fit: contain;
  display: block;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.sender-signature-canvas {
  width: 100%;
  height: 120px;
  display: block;
  border: 1px solid #bfc7ba;
  border-radius: 8px;
  background: #fffef8;
  touch-action: none;
  cursor: crosshair;
}

.pdf-sender-signature-target {
  position: absolute;
  display: grid;
  place-items: center;
  border: 2px dashed var(--brand-2);
  border-radius: 4px;
  background: rgba(232, 247, 241, 0.7);
  color: #0f6254;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  z-index: 3;
}

.pdf-sender-signature-target:hover {
  background: rgba(232, 247, 241, 0.96);
}

.pdf-signature-pad {
  position: absolute;
  border: 2px dashed var(--brand-2);
  border-radius: 4px;
  background: rgba(255, 254, 248, 0.62);
  box-shadow: 0 5px 16px rgba(31, 42, 34, 0.18);
  z-index: 6;
  overflow: visible;
}

.pdf-signature-pad.sender-pad span {
  left: auto;
  right: -2px;
  bottom: calc(100% + 4px);
}

.pdf-signature-pad canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.pdf-signature-pad img {
  position: absolute;
  inset: 1px;
  width: calc(100% - 2px);
  height: calc(100% - 2px);
  object-fit: contain;
  pointer-events: none;
}

.pdf-signature-pad b {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #0f6254;
  font-size: 10px;
  pointer-events: none;
}

.pdf-signature-pad img[src] + b {
  display: none;
}

.pdf-signature-pad span {
  position: absolute;
  left: -2px;
  bottom: calc(100% + 4px);
  padding: 3px 6px;
  border-radius: 4px;
  background: #e6f3ef;
  color: #0f6254;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
  box-shadow: 0 4px 10px rgba(31, 42, 34, 0.14);
}

.pdf-signature-tools {
  position: absolute;
  right: -2px;
  top: calc(100% + 4px);
  display: none;
}

.pdf-signature-pad:hover .pdf-signature-tools,
.pdf-signature-pad:focus-within .pdf-signature-tools {
  display: block;
}

.pdf-signature-tools .btn {
  min-height: 28px;
  padding: 0 8px;
  font-size: 11px;
}

.signer-stage {
  margin-top: 18px;
}

.signer-flow {
  display: block;
}

.signer-submit-panel {
  max-width: 900px;
  margin: 18px auto 0;
}

.signature-modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(18, 28, 22, 0.48);
  z-index: 30;
}

.signature-modal.open {
  display: grid;
}

.signature-modal-box {
  width: min(820px, 100%);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
}

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

.signature-modal-canvas {
  width: 100%;
  height: 260px;
  display: block;
  margin-bottom: 12px;
  border: 1px solid #bfc7ba;
  border-radius: 8px;
  background:
    linear-gradient(to bottom, transparent calc(100% - 62px), rgba(18, 107, 91, 0.15) calc(100% - 61px), transparent calc(100% - 60px)),
    #fffef8;
  touch-action: none;
  cursor: crosshair;
}

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

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

.stats div {
  padding: 15px;
}

.stats span {
  color: var(--muted);
  font-size: 12px;
}

.stats strong {
  display: block;
  margin-top: 7px;
  font-size: 26px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  padding: 17px;
}

.panel.wide {
  min-width: 0;
}

.panel.narrow {
  max-width: 520px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

label span {
  color: #3d453b;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
  background: white;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(18, 107, 91, 0.13);
}

.check {
  grid-template-columns: 20px 1fr;
  align-items: start;
}

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

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

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3ec;
  color: var(--ink);
  padding: 0 13px;
  cursor: pointer;
}

.btn.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

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

.table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.row {
  display: grid;
  grid-template-columns: 1.5fr 1fr 100px 120px;
  gap: 12px;
  align-items: center;
  padding: 13px;
  border-bottom: 1px solid var(--line);
}

.row:last-child {
  border-bottom: 0;
}

.row.head {
  background: #eef3ec;
  color: #4a5247;
  font-size: 12px;
  font-weight: 800;
}

.row strong,
.row small {
  display: block;
}

.badge {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
}

.badge.sent {
  background: #fff3d9;
  color: #805500;
}

.badge.draft {
  background: #ecefec;
  color: #4c5349;
}

.badge.done {
  background: #e1f4e7;
  color: #16733f;
}

.meta {
  display: grid;
  gap: 10px;
  margin: 0 0 14px;
}

.meta div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 10px;
}

.meta dt {
  color: var(--muted);
  font-size: 12px;
}

.meta dd {
  margin: 0;
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline div {
  display: grid;
  gap: 3px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.timeline div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.timeline time,
.timeline span {
  color: var(--muted);
  font-size: 12px;
}

.field-editor {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.field-editor label {
  margin: 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.field-editor .required-field {
  border-color: #dfc264;
  background: #fffbed;
}

.field-editor b,
.field-editor em {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11px;
  font-style: normal;
}

.field-editor b {
  background: #fff0ba;
  color: #7d5600;
}

.field-editor em {
  background: #eaf1ea;
  color: var(--muted);
}

.send-box {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

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

.viewer {
  margin-top: 18px;
  overflow: hidden;
}

.viewer iframe {
  width: 100%;
  height: 76vh;
  display: block;
  border: 0;
  background: white;
}

.pdf-edit-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.pdf-edit-side {
  position: sticky;
  top: 18px;
}

.pdf-edit-stage {
  min-width: 0;
}

.pdf-pages {
  display: grid;
  gap: 18px;
  min-height: 70vh;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(18, 107, 91, 0.055) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(18, 107, 91, 0.055) 25%, transparent 25%),
    #eef2ec;
  background-size: 28px 28px;
  overflow: auto;
}

.pdf-page-sheet {
  position: relative;
  margin: 0 auto;
  background: white;
  box-shadow: 0 16px 34px rgba(31, 42, 34, 0.18);
}

.pdf-page-sheet canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.pdf-field {
  position: absolute;
  display: block;
  margin: 0;
  padding: 0;
  border: 2px solid #d0a717;
  border-radius: 4px;
  background: rgba(255, 251, 221, 0.52);
  box-shadow: 0 4px 12px rgba(75, 61, 5, 0.12);
  z-index: 1;
}

.pdf-field.is-optional {
  border-color: var(--brand-2);
  background: rgba(238, 247, 242, 0.55);
}

.pdf-field:focus-within {
  z-index: 8;
  box-shadow: 0 0 0 3px rgba(18, 107, 91, 0.16), 0 7px 18px rgba(31, 42, 34, 0.22);
}

.pdf-field span {
  position: absolute;
  left: -2px;
  bottom: calc(100% + 3px);
  max-width: 190px;
  display: none;
  min-height: 18px;
  padding: 3px 6px;
  border-radius: 4px;
  background: #fff3c7;
  color: #674900;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 10px rgba(75, 61, 5, 0.14);
  pointer-events: none;
}

.pdf-field:hover span,
.pdf-field:focus-within span {
  display: block;
}

.pdf-field.is-optional span {
  background: #e6f3ef;
  color: #0f6254;
}

.pdf-field input,
.pdf-field select,
.pdf-field textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 2px;
  padding: 0 4px;
  font-size: 11px;
  line-height: 1.1;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: none;
}

.pdf-field input:focus,
.pdf-field select:focus,
.pdf-field textarea:focus {
  box-shadow: none;
}

.pdf-field textarea {
  height: 100%;
  min-height: 0;
  resize: none;
}

.flash {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.flash div {
  padding: 11px 13px;
  border: 1px solid #efc4b7;
  border-radius: 8px;
  background: #fff0eb;
  color: var(--danger);
}

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

@media (max-width: 940px) {
  .shell,
  .grid,
  .stats,
  .pdf-edit-layout {
    grid-template-columns: 1fr;
  }

  .pdf-edit-side {
    position: static;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 14px;
  }

  .note {
    display: none;
  }

  .page-head {
    flex-direction: column;
  }

  .row,
  .row.head {
    grid-template-columns: 1fr;
  }

  .row.head {
    display: none;
  }
}
