/* ============================================================
   style.css  —  Awesome Construction Corp · Contract System
   ============================================================ */

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:       #c0392b;     /* deep red — primary CTA */
  --brand-dk:    #a93226;
  --accent:      #1a1a2e;     /* near-black navy */
  --surface:     #ffffff;
  --bg:          #f4f5f7;
  --border:      #dde1e7;
  --text:        #1d2229;
  --muted:       #6b7280;
  --success:     #16a34a;
  --err:         #dc2626;
  --radius:      10px;
  --shadow:      0 2px 12px rgba(0,0,0,.09);
  --font:        'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  font-family:    var(--font);
  background:     var(--bg);
  color:          var(--text);
  font-size:      15px;
  line-height:    1.6;
  min-height:     100vh;
}

/* ── Layout ───────────────────────────────────────────────── */
.page-wrap {
  max-width:      880px;
  margin:         0 auto;
  padding:        1.5rem 1rem 4rem;
}

/* ── Header ───────────────────────────────────────────────── */
.site-header {
  display:        flex;
  align-items:    center;
  gap:            1rem;
  background:     var(--accent);
  color:          #fff;
  border-radius:  var(--radius);
  padding:        1rem 1.4rem;
  margin-bottom:  1.5rem;
}

.site-header .logo { font-size: 2rem; line-height: 1; }
.site-header h1    { font-size: 1.25rem; font-weight: 700; letter-spacing: .3px; }
.site-header .tagline { font-size: .82rem; opacity: .75; }
.site-header .btn-ghost { margin-left: auto; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background:     var(--surface);
  border:         1px solid var(--border);
  border-radius:  var(--radius);
  padding:        2rem 2.2rem;
  box-shadow:     var(--shadow);
  margin-bottom:  1.5rem;
}

.card.narrow   { max-width: 420px; }
.card.wide     { max-width: 100%; }
.center-card   { margin-left: auto; margin-right: auto; }

/* ── Fieldsets ────────────────────────────────────────────── */
fieldset {
  border:         1px solid var(--border);
  border-radius:  var(--radius);
  padding:        1.2rem 1.4rem;
  margin-bottom:  1.4rem;
}

legend {
  font-weight:    700;
  font-size:      .9rem;
  color:          var(--accent);
  padding:        0 .5rem;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── Form Fields ──────────────────────────────────────────── */
.field        { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .9rem; }
.field:last-child { margin-bottom: 0; }
.field label  { font-size: .85rem; font-weight: 600; color: var(--accent); }

input[type="text"],
input[type="email"],
input[type="date"],
input[type="number"],
input[type="password"],
select,
textarea {
  width:          100%;
  border:         1px solid var(--border);
  border-radius:  6px;
  padding:        .55rem .75rem;
  font-family:    var(--font);
  font-size:      .92rem;
  color:          var(--text);
  background:     #fff;
  transition:     border-color .15s, box-shadow .15s;
  outline:        none;
}

input:focus, select:focus, textarea:focus {
  border-color:  var(--brand);
  box-shadow:    0 0 0 3px rgba(192,57,43,.13);
}

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

.req           { color: var(--brand); }
.hint-label    { font-weight: 400; color: var(--muted); font-size: .8rem; }
.field-note    { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

/* ── Grid helpers ─────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.pay-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }

@media (max-width: 600px) {
  .grid-2, .grid-3, .pay-grid { grid-template-columns: 1fr; }
  .card { padding: 1.2rem 1rem; }
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display:        inline-flex;
  align-items:    center;
  justify-content:center;
  gap:            .4rem;
  border:         none;
  border-radius:  7px;
  padding:        .6rem 1.2rem;
  font-family:    var(--font);
  font-size:      .9rem;
  font-weight:    600;
  cursor:         pointer;
  transition:     background .15s, transform .1s;
  text-decoration:none;
}

.btn:active { transform: scale(.97); }

.btn-primary  { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dk); }

.btn-ghost    { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); }
.btn-ghost:hover { background: rgba(255,255,255,.1); }

.btn-sm       { padding: .35rem .7rem; font-size: .8rem; }
.btn-lg       { padding: .8rem 2rem;   font-size: 1rem; }
.btn-block    { display: flex; width: 100%; }

.form-actions { margin-top: 1.8rem; display: flex; justify-content: flex-end; }

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
  padding:        .7rem 1rem;
  border-radius:  7px;
  font-size:      .88rem;
  font-weight:    500;
  margin-bottom:  1rem;
}
.alert-err { background: #fef2f2; color: var(--err); border: 1px solid #fecaca; }
.alert-ok  { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

/* ── Link box (signing URL) ───────────────────────────────── */
.link-box {
  display:        flex;
  gap:            .5rem;
  align-items:    center;
  background:     #f8f9fb;
  border:         1px solid var(--border);
  border-radius:  7px;
  padding:        .5rem .75rem;
  margin-top:     .75rem;
}
.link-box input { border: none; background: transparent; flex: 1; font-size: .82rem; color: var(--brand); }

/* ── Success icon ─────────────────────────────────────────── */
.success-icon { font-size: 2.5rem; text-align: center; margin-bottom: .5rem; }

/* ── Contract body styling ────────────────────────────────── */
.contract-body { line-height: 1.7; }
.contract-title { text-align: center; font-size: 1.35rem; margin-bottom: 1.2rem; letter-spacing: .5px; }
.contract-body h3 { font-size: 1rem; margin: 1.4rem 0 .4rem; color: var(--accent); border-bottom: 1px solid #eee; padding-bottom: 3px; }
.contract-body p  { margin-bottom: .6rem; }
.services-block   { padding: .5rem 0 .5rem 1rem; }
.services-block .svc-heading { font-weight: 700; margin-top: .8rem; }
.services-block ul { margin-left: 1.2rem; }
.services-block li { margin: .15rem 0; }

/* ── Payment table ────────────────────────────────────────── */
.pay-table {
  width:          100%;
  border-collapse:collapse;
  margin:         1rem 0;
  font-size:      .9rem;
}
.pay-table th, .pay-table td {
  border:         1px solid var(--border);
  padding:        .5rem .8rem;
  text-align:     left;
}
.pay-table th   { background: #f0f0f4; font-weight: 700; }
.pay-table tr:nth-child(even) { background: #fafafa; }

/* ── Signature section ────────────────────────────────────── */
.sig-card   { border-top: 3px solid var(--brand); }
.sig-card h2 { color: var(--brand); margin-bottom: .75rem; }

.sig-wrap   { margin: 1rem 0; }
.sig-wrap label { font-weight: 600; font-size: .88rem; display: block; margin-bottom: .5rem; }

#sigCanvas {
  border:         2px solid var(--border);
  border-radius:  8px;
  width:          100%;
  display:        block;
  cursor:         crosshair;
  background:     #fdfcff;
  touch-action:   none; /* critical for mobile */
}

.sig-actions { margin-top: .5rem; text-align: right; }

.checkbox-row {
  display:        flex;
  align-items:    flex-start;
  gap:            .6rem;
  margin:         1.2rem 0 1.4rem;
  font-size:      .9rem;
}
.checkbox-row input[type="checkbox"] { margin-top: 3px; width: auto; flex-shrink: 0; }

.legal-note {
  font-size:      .78rem;
  color:          var(--muted);
  margin-top:     .8rem;
  text-align:     center;
}

/* ── Loading overlay ──────────────────────────────────────── */
.overlay {
  position:       fixed;
  inset:          0;
  background:     rgba(0,0,0,.55);
  display:        flex;
  flex-direction: column;
  align-items:    center;
  justify-content:center;
  gap:            1rem;
  color:          #fff;
  font-size:      1rem;
  z-index:        999;
}

.spinner {
  width:          44px;
  height:         44px;
  border:         4px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius:  50%;
  animation:      spin .75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Dynamic Payment Schedule ─────────────────────────────── */
.pay-schedule-label {
  margin: 1.2rem 0 .6rem;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .3rem;
}
.pay-schedule-head {
  display: grid;
  grid-template-columns: 32px 1fr 110px 120px 36px;
  gap: .5rem;
  padding: .35rem .5rem;
  background: #f0f0f4;
  border-radius: 6px 6px 0 0;
  border: 1px solid var(--border);
  font-size: .78rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.pay-row {
  display: grid;
  grid-template-columns: 32px 1fr 110px 120px 36px;
  gap: .5rem;
  align-items: center;
  padding: .45rem .5rem;
  border: 1px solid var(--border);
  border-top: none;
  background: #fff;
  transition: background .1s;
}
.pay-row:hover { background: #fafbff; }
.pay-row:last-child { border-radius: 0 0 6px 6px; }
.pay-row input { padding: .38rem .5rem; font-size: .88rem; border-radius: 5px; }
.ph-num      { text-align: center; color: var(--muted); font-size: .8rem; font-weight: 700; }
.ph-milestone{ min-width: 0; }
.ph-milestone input { width: 100%; }
.ph-pct      { display: flex; align-items: center; gap: 3px; }
.ph-pct input { width: 68px; }
.pct-sym     { font-size: .85rem; color: var(--muted); }
.ph-amt input { width: 100%; }
.ph-del      { display: flex; justify-content: center; }
.row-num {
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; background: var(--accent); color: #fff;
  border-radius: 50%; font-size: .72rem; font-weight: 700; margin: 0 auto;
}
.btn-del {
  background: none; border: 1px solid #fca5a5; color: #dc2626;
  border-radius: 5px; width: 26px; height: 26px; font-size: .75rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.btn-del:hover { background: #fef2f2; }
.pay-footer {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: .6rem; flex-wrap: wrap; gap: .5rem;
}
.btn-add {
  background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe;
  border-radius: 7px; padding: .4rem .9rem; font-size: .85rem; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.btn-add:hover { background: #dbeafe; }
.pct-summary { display: flex; align-items: center; gap: .5rem; font-size: .88rem; }
.pct-badge {
  display: inline-block; padding: .2rem .6rem; border-radius: 99px;
  font-size: .8rem; font-weight: 700;
}
.pct-ok  { background: #dcfce7; color: #15803d; }
.pct-err { background: #fee2e2; color: #b91c1c; }
.pct-warn { color: #b45309; font-size: .8rem; font-weight: 600; }
@media (max-width: 600px) {
  .pay-schedule-head { display: none; }
  .pay-row { grid-template-columns: 28px 1fr; }
}
