:root {
  --bg0: #071824;
  --bg1: #0d2a3d;
  --bg2: #12364d;
  --panel: rgba(255, 255, 255, 0.94);
  --ink: #122033;
  --muted: #5b6b7c;
  --line: #d5e0ea;
  --brand: #0b3a5b;
  --accent: #1f8a7a;
  --accent-2: #c9a227;
  --danger: #b42318;
  --ok: #067647;
  --shadow: 0 18px 50px rgba(7, 24, 36, 0.28);
  --radius: 18px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(31, 138, 122, 0.35), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(201, 162, 39, 0.22), transparent 50%),
    linear-gradient(160deg, var(--bg0), var(--bg1) 45%, var(--bg2));
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  color: #e8f1f7;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
  color: inherit;
}

.brand-logo {
  display: block;
  height: 48px;
  width: auto;
  max-width: min(200px, 42vw);
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.brand-mark strong {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2.6vw, 1.75rem);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.brand-mark .brand-text > span {
  font-size: 0.92rem;
  opacity: 0.78;
}

@media (max-width: 640px) {
  .brand-text strong {
    font-size: 1.1rem;
  }
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  padding: 1.35rem 1.5rem 1rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f7fafc);
}

.panel-head h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  color: var(--brand);
}

.panel-head p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.steps {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.35rem;
  padding: 0.85rem 1rem;
  background: #f2f6f9;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.step-pill {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.45rem 0.25rem;
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

a.step-pill:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.step-pill.active {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

.step-pill.done {
  color: var(--ok);
  border-color: #abefc6;
  background: #ecfdf3;
}

.panel-body { padding: 1.35rem 1.5rem 1.6rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.95rem 1rem;
  align-items: start;
}

.grid.one { grid-template-columns: 1fr; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

label.field {
  /* Block (not flex-column) so label text + .req stay on one line,
     and inputs across a grid row share the same baseline. */
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--brand);
}

label.field > input,
label.field > select,
label.field > textarea,
label.field > .password-field,
label.field > .check-row,
label.field > div.check-row {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
}

label.field span.hint {
  display: block;
  margin-top: 0.25rem;
  font-weight: 400;
  color: var(--muted);
  font-size: 0.78rem;
}

.req {
  color: var(--danger);
  font-weight: 800;
  margin-left: 0.15rem;
  white-space: nowrap;
}

input:required:invalid,
select:required:invalid,
textarea:required:invalid {
  border-color: #f7b4ae;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="password"] {
  letter-spacing: 0.12em;
  font-size: 1.05rem;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 138, 122, 0.18);
}

textarea { min-height: 90px; resize: vertical; }

.check-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.35rem;
  font-weight: 500;
  color: var(--ink);
}

.check-row input { width: 1rem; height: 1rem; }

.section-title {
  margin: 0.4rem 0 0.2rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--brand);
}

.section-note {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.actions .btn {
  align-self: center;
  height: auto;
  min-height: 0;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 0.75rem 1.25rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-secondary {
  background: #e8eef3;
  color: var(--brand);
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #167a6c);
  color: #fff;
}
.btn-dark {
  background: var(--brand);
  color: #fff;
}
.btn-ghost {
  background: transparent;
  color: #dff0ea;
  border: 1px solid rgba(255,255,255,0.25);
}
.btn-danger {
  background: #b42318;
  color: #fff;
}
.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(7, 24, 36, 0.55);
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem;
}

.modal-card h3 {
  margin: 0 0 0.45rem;
  font-family: var(--font-display);
  color: var(--brand);
  font-size: 1.2rem;
}

.modal-card p {
  margin: 0 0 1.1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
}

.sig-tabs {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  background: #fbfcfd;
}

.sig-tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
}

.sig-tab-row .btn.is-active {
  background: var(--brand);
  color: #fff;
}

.sig-pad-wrap {
  border: 1px dashed #9db0c1;
  border-radius: 12px;
  background:
    linear-gradient(180deg, #fff, #f7fafc);
  overflow: hidden;
}

#signature-pad {
  display: block;
  width: 100%;
  height: 180px;
  touch-action: none;
  cursor: crosshair;
}

.sig-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.sig-preview-box {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.sig-preview {
  display: block;
  max-width: min(420px, 100%);
  max-height: 120px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.4rem 0.6rem;
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}
.alert-error { background: #fef3f2; color: var(--danger); border: 1px solid #fecdca; }
.alert-ok { background: #ecfdf3; color: var(--ok); border: 1px solid #abefc6; }
.alert-info { background: #eff8ff; color: #175cd3; border: 1px solid #b2ddff; }

.review-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  background: #fbfcfd;
  margin-bottom: 0.85rem;
}

.review-card h3 {
  margin: 0 0 0.55rem;
  font-size: 0.95rem;
  color: var(--brand);
}

.review-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.9rem;
}

.review-grid dt { color: var(--muted); }
.review-grid dd { margin: 0; font-weight: 600; }

.pdf-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}

.pdf-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  background: linear-gradient(180deg, #fff, #f5f9fb);
}

.pdf-card h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  color: var(--brand);
}

.pdf-card p {
  margin: 0 0 0.9rem;
  color: var(--muted);
  font-size: 0.88rem;
  min-height: 2.4em;
}

.pdf-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 0.7rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.admin-table th { color: var(--muted); font-weight: 600; }
.token-link {
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge-draft { background: #f2f4f7; color: #344054; }
.badge-submitted { background: #eff8ff; color: #175cd3; }
.badge-changes_requested { background: #fffaeb; color: #b54708; }
.badge-completed { background: #ecfdf3; color: var(--ok); }

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.brand-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
}

.admin-user-chip {
  font-size: 0.85rem;
  opacity: 0.85;
  white-space: nowrap;
}

.login-panel {
  width: min(420px, 100%);
  margin: 2rem auto 0;
}

.unlock-panel {
  width: min(460px, 100%);
  margin: 2.5rem auto 0;
}

.unlock-docs {
  display: grid;
  gap: 0.2rem;
  margin: 0 0 1.15rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: linear-gradient(180deg, #f4faf8, #eef5f8);
  border: 1px solid #d7e6e2;
}

.unlock-docs-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.unlock-docs-value {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--brand);
  line-height: 1.35;
}

.unlock-submit {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.9rem 1.25rem;
  font-size: 1.02rem;
}

.login-form {
  display: grid;
  gap: 0.95rem;
}

.password-field {
  position: relative;
  display: flex;
  align-items: center;
}

.password-field input {
  padding-right: 4.2rem;
}

.password-toggle {
  position: absolute;
  right: 0.45rem;
  border: none;
  background: #eef5f8;
  color: var(--brand);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
}

.password-toggle:hover {
  background: #dceaf1;
}

.template-editor {
  display: grid;
  gap: 0.85rem;
}

.template-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: #fbfcfd;
}

.template-toolbar {
  margin-bottom: 1rem;
}

.field-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  background: linear-gradient(180deg, #fff, #f7fafc);
  display: grid;
  gap: 0.65rem;
}

.field-card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
}

.field-card-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand);
  background: #eef5f8;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  margin-right: 0.35rem;
}

.field-card-toggles {
  display: grid;
  gap: 0.45rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f4f8fa;
}

.template-editor-actions {
  position: sticky;
  bottom: 0.75rem;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
  box-shadow: 0 10px 30px rgba(7, 24, 36, 0.12);
}

.preview-frame {
  width: 100%;
  height: 75vh;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

@media (max-width: 860px) {
  .grid, .grid.three, .pdf-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .steps { grid-template-columns: repeat(4, minmax(70px, 1fr)); }
  .review-grid { grid-template-columns: 1fr; }
  .actions { flex-direction: column-reverse; }
  .btn { width: 100%; }
}
