:root {
  --ink: #1f3345;
  --muted: #64748b;
  --line: #d5e0ec;
  --field-bg: #f7f9fc;
  --bg: #eef2f6;
  --card: #fff;
  --primary: #1f6f5c;
  --primary-ink: #fff;
  --mine: #e6f4ef;
  --mine-line: #1f6f5c;
  --danger: #b42318;
  --ok: #157f3b;
  --wait: #a15c07;
  --radius: 10px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 16px 12px 96px;
}

.container.wide {
  max-width: 900px;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 8px;
}

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

.small {
  font-size: 0.85rem;
}

.center {
  text-align: center;
}

.visually-hidden {
  position: absolute;
  left: -9999px;
}

/* Cards & layout */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.08);
  padding: 20px;
  margin-bottom: 16px;
}

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

.card-head h1 {
  margin: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.brand {
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.1rem;
}

.page-head {
  margin: 0 4px 16px;
}

.back {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 700;
  margin: 0 0 4px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--field-bg);
}

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

.btn.primary:hover {
  filter: brightness(1.08);
}

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

.btn.ghost {
  background: transparent;
}

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

.btn.small {
  padding: 6px 12px;
  font-size: 0.9rem;
}

.btn.big {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
}

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  text-decoration: underline;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Form controls */
input[type='text'],
input[type='password'],
input[type='date'],
input:not([type]) {
  width: 100%;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 40px;
}

input:focus-visible,
.btn:focus-visible,
.link-btn:focus-visible {
  outline: 3px solid rgb(31 111 92 / 0.35);
  outline-offset: 1px;
}

.form-error {
  color: var(--danger);
  font-weight: 600;
}

.banner {
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0;
}

.banner.success {
  background: #e7f6ec;
  color: #0f5132;
}

/* Badges & status */
.badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge.ok {
  background: #e7f6ec;
  color: var(--ok);
}

.badge.wait {
  background: #fdf3e2;
  color: var(--wait);
}

.status-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 16px;
  font-size: 0.92rem;
}

.status-list .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.status-list .ok .dot {
  background: var(--ok);
}

.status-list .wait .dot {
  background: #e3a008;
}

/* Contract (mirrors the PDF template) */
.paper {
  padding: 28px 32px;
}

.contract header {
  text-align: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 20px;
}

.contract h1 {
  font-size: 1.45rem;
  letter-spacing: 0.01em;
}

.contract .subtitle {
  font-style: italic;
  color: var(--muted);
  margin: 0;
}

.contract section {
  margin-bottom: 22px;
}

.contract h2 {
  font-size: 0.98rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.contract p {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.contract .row {
  display: flex;
  gap: 12px;
}

.contract .row > .field {
  flex: 1 1 0;
  min-width: 0;
}

.contract .row > .field.grow {
  flex: 1.8 1 0;
}

.contract .row > .field.narrow {
  flex: 0.6 1 0;
}

.field {
  margin-bottom: 10px;
}

.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 3px;
}

.field .value {
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field-bg);
  overflow-wrap: anywhere;
}

.field .value.empty {
  color: #a3b1c2;
}

.field.mine label {
  color: var(--primary);
  font-weight: 700;
}

.field.mine input {
  border: 2px solid var(--mine-line);
  background: var(--mine);
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  margin-bottom: 12px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
}

.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.sig-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 28px;
}

.sig {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  min-height: 58px;
}

.sig-label {
  width: 92px;
  flex: none;
  font-size: 0.85rem;
  color: var(--muted);
  padding-bottom: 4px;
}

.sig-line {
  flex: 1;
  min-width: 0;
  border-bottom: 1px solid #b7c7da;
  min-height: 50px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 3px;
}

.sig-line img {
  max-height: 48px;
  max-width: 100%;
}

.sig-line .pending {
  color: #a3b1c2;
  font-size: 0.8rem;
}

.sig-line .signed {
  color: var(--ok);
  font-weight: 600;
  font-size: 0.85rem;
}

.sig.mine .sig-line {
  border-bottom: 2px solid var(--mine-line);
  background: var(--mine);
}

.sig.mine .sig-label {
  color: var(--primary);
  font-weight: 700;
}

.contract footer {
  text-align: center;
  font-style: italic;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 24px;
}

/* Signature input */
.sig-input .hint {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.sig-canvas {
  display: block;
  width: 100%;
  height: 180px;
  border: 2px dashed #9fb3c8;
  border-radius: 8px;
  background: #fff linear-gradient(to top, transparent 44px, #c9d6e4 44px, #c9d6e4 45px, transparent 45px);
  cursor: crosshair;
}

.sig-preview {
  display: block;
  max-width: 100%;
  max-height: 120px;
  margin: 8px auto;
}

.sig-saved {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.sig-input .actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

.sign-card h2 {
  margin-bottom: 12px;
}

.agree {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 16px 0;
  font-size: 0.95rem;
}

.agree input {
  width: 22px;
  height: 22px;
  margin-top: 1px;
  flex: none;
  accent-color: var(--primary);
}

/* Admin */
.login {
  max-width: 380px;
  margin: 12vh auto 0;
}

.login .btn {
  width: 100%;
  margin-top: 8px;
}

.contract-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.contract-list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 4px;
  border-top: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}

.contract-list a:hover {
  background: var(--field-bg);
}

.link-row {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.link-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.link-head .badge {
  margin-left: auto;
}

.link-body {
  display: flex;
  gap: 6px;
}

.link-body input {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.link-actions {
  display: flex;
  gap: 16px;
  margin-top: 6px;
}

.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px max(12px, calc((100vw - 900px) / 2 + 12px));
  background: rgb(255 255 255 / 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(6px);
  flex-wrap: wrap;
}

.action-bar .spacer {
  flex: 1;
}

/* Toasts */
#toasts {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}

.toast {
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgb(15 23 42 / 0.2);
  font-weight: 600;
}

.toast.success {
  background: var(--ok);
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 640px) {
  .paper {
    padding: 18px 14px;
  }

  .card {
    padding: 16px;
  }

  .contract h1 {
    font-size: 1.15rem;
  }

  .contract .row,
  .two-col {
    flex-direction: column;
    display: flex;
    gap: 0;
  }

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

  .status-list {
    grid-template-columns: 1fr;
  }

  .action-bar .spacer {
    display: none;
  }

  .action-bar .save-status {
    width: 100%;
  }

  .action-bar .btn {
    flex: 1;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .action-bar,
  .sign-card,
  .intro {
    display: none;
  }

  .card {
    box-shadow: none;
  }
}
