/* ============================================================
   Digital SOW Platform — Styles
   ============================================================ */

:root {
  --primary: #007C7C;
  --primary-dark: #005a5a;
  --secondary: #1a1a2e;
  --accent: #e8b931;
  --light: #f0f9f9;
  --text: #333;
  --text-light: #666;
  --text-muted: #999;
  --border: #e0e0e0;
  --bg: #f5f5f5;
  --white: #fff;
  --success: #1b7a3d;
  --error: #dc2626;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }


body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Loading & Error States
   ============================================================ */

.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--white);
  z-index: 9999;
  gap: 16px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-overlay p {
  color: var(--text-light);
  font-size: 14px;
}

.error-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--white);
}

.error-content {
  text-align: center;
  padding: 40px;
}

.error-content h1 {
  font-size: 24px;
  color: var(--secondary);
  margin-bottom: 8px;
}

.error-content p {
  color: var(--text-light);
}

/* ============================================================
   Document Header Bar
   ============================================================ */

.doc-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--secondary);
  color: var(--white);
  padding: 12px 0;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.header-logo {
  height: 36px;
  width: auto;
  object-fit: contain;
  border-radius: 4px;
}

.header-text {
  display: flex;
  flex-direction: column;
}

.header-company-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.header-tagline {
  font-size: 11px;
  opacity: 0.7;
  letter-spacing: 0.01em;
}

.status-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
}

.status-pending {
  background: rgba(232, 185, 49, 0.2);
  color: var(--accent);
}

.status-signed {
  background: rgba(27, 122, 61, 0.2);
  color: #4ade80;
}

/* ============================================================
   Document Container
   ============================================================ */

.document-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ============================================================
   SOW Content Styles
   ============================================================ */

.sow-content {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 56px;
  margin: 32px 0;
}

.sow-content h1 {
  font-size: 28px;
  color: var(--secondary);
  margin-bottom: 4px;
  line-height: 1.2;
}

.sow-content .sow-subtitle {
  font-size: 16px;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 24px;
}

.sow-content .sow-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
  padding: 20px;
  background: var(--light);
  border-radius: var(--radius);
  border-left: 4px solid var(--primary);
}

.sow-content .sow-meta dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
}

.sow-content .sow-meta dd {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  margin-bottom: 8px;
}

.sow-content .sow-divider {
  border: none;
  border-top: 2px solid var(--border);
  margin: 32px 0;
}

.sow-content h2 {
  font-size: 20px;
  color: var(--secondary);
  margin: 32px 0 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary);
  display: inline-block;
}

.sow-content h3 {
  font-size: 16px;
  color: var(--primary);
  margin: 24px 0 8px;
}

.sow-content p {
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.7;
}

.sow-content ul, .sow-content ol {
  margin: 8px 0 16px 20px;
  font-size: 14px;
}

.sow-content li {
  margin-bottom: 6px;
  line-height: 1.6;
}

/* Tables */
.sow-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 24px;
  font-size: 13px;
}

.sow-content thead th {
  background: var(--secondary);
  color: var(--white);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.sow-content tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.sow-content tbody tr:nth-child(even) td {
  background: #fafafa;
}

.sow-content tbody tr:last-child td {
  border-bottom: 2px solid var(--secondary);
}

/* Investment highlight table */
.sow-content table.investment-table tbody tr:last-child td {
  background: var(--light);
  font-weight: 700;
  color: var(--secondary);
  border-bottom: 3px solid var(--primary);
}

.sow-content table.investment-table .savings-cell {
  color: var(--success);
  font-weight: 700;
}

/* Callout box */
.sow-content .callout {
  background: var(--light);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px 24px;
  margin: 16px 0 24px;
  text-align: center;
}

.sow-content .callout p {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

/* Notes / italic blocks */
.sow-content .note {
  font-size: 12px;
  color: var(--text-light);
  font-style: italic;
}

/* ============================================================
   Signature Section
   ============================================================ */

.signature-section {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 56px;
  margin: 0 0 32px;
  border-top: 4px solid var(--primary);
}

.section-heading {
  font-size: 22px;
  color: var(--secondary);
  margin-bottom: 8px;
}

.signature-intro {
  color: var(--text-light);
  font-size: 14px;
  margin-bottom: 32px;
}

.signature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
}

.signature-block h3 {
  font-size: 16px;
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.sig-field {
  margin-bottom: 16px;
}

.sig-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.required {
  color: var(--error);
}

.sig-field input[type="text"],
.sig-field input[type="date"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.2s;
}

.sig-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 124, 124, 0.1);
}

.sig-field input.error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

/* Signature Pad */
.signature-pad-wrapper {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 6px;
  background: #fcfcfc;
  overflow: hidden;
  transition: border-color 0.2s;
}

.signature-pad-wrapper:hover,
.signature-pad-wrapper.active {
  border-color: var(--primary);
}

.signature-pad-wrapper.has-signature {
  border-style: solid;
  border-color: var(--success);
}

.signature-pad {
  width: 100%;
  height: 120px;
  display: block;
  cursor: crosshair;
}

.sig-clear-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.05);
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.sig-clear-btn:hover {
  background: rgba(220, 38, 38, 0.1);
  color: var(--error);
}

.sig-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-style: italic;
}

/* Pre-signed area */
.presigned-value {
  font-size: 14px;
  color: var(--text);
  padding: 8px 0;
}

.presigned-sig-img {
  max-width: 240px;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  background: #fcfcfc;
}

/* Signed confirmation */
.signed-confirmation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 24px;
  background: rgba(27, 122, 61, 0.08);
  border: 1px solid rgba(27, 122, 61, 0.2);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  width: 100%;
}

.signed-confirmation strong {
  color: var(--success);
}

/* Action Buttons */
.signature-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 124, 124, 0.3);
}

.btn-secondary {
  background: var(--white);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #f5f5f5;
}

.btn-sign {
  font-size: 16px;
  padding: 14px 36px;
}

/* ============================================================
   Footer
   ============================================================ */

.doc-footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 12px;
  max-width: 900px;
  margin: 0 auto;
}

.doc-footer p {
  margin-bottom: 4px;
}

/* ============================================================
   Print Styles
   ============================================================ */

@media print {
  body { background: white; }
  .doc-header, .doc-footer, .signature-actions, .sig-clear-btn, .sig-hint { display: none; }
  .document-container { max-width: 100%; padding: 0; }
  .sow-content, .signature-section {
    box-shadow: none;
    border-radius: 0;
    padding: 24px 0;
    margin: 0;
  }
  .signature-section { border-top: 2px solid #333; page-break-inside: avoid; }
  .signature-pad-wrapper { border-style: solid; border-color: #ccc; }
}

/* ============================================================
   PDF Generation Mode — tighter layout
   ============================================================ */

body.pdf-mode .doc-header,
body.pdf-mode .doc-footer,
body.pdf-mode .signature-actions,
body.pdf-mode .sig-clear-btn,
body.pdf-mode .sig-hint,
body.pdf-mode .btn { display: none; }

body.pdf-mode .document-container { max-width: 100%; padding: 0 12px; }

body.pdf-mode .sow-content,
body.pdf-mode .signature-section {
  box-shadow: none;
  padding: 24px 32px;
  margin: 0;
}

body.pdf-mode .sow-content h1 { font-size: 24px; }
body.pdf-mode .sow-content h2 { font-size: 17px; margin: 20px 0 8px; }
body.pdf-mode .sow-content h3 { font-size: 14px; margin: 16px 0 6px; }
body.pdf-mode .sow-content p { font-size: 12px; margin-bottom: 8px; }
body.pdf-mode .sow-content table { font-size: 11px; }
body.pdf-mode .sow-content thead th { padding: 6px 10px; font-size: 10px; }
body.pdf-mode .sow-content tbody td { padding: 6px 10px; }

body.pdf-mode .signature-section { border-top: 2px solid var(--primary); padding-top: 20px; }
body.pdf-mode .signature-pad { height: 80px; }

/* Signed state: replace canvas with image */
body.pdf-mode .signature-pad-wrapper { border-style: solid; }
body.pdf-mode .sig-field input {
  border: none;
  padding: 4px 0;
  font-weight: 600;
  font-size: 14px;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
  .sow-content { padding: 24px 20px; }
  .signature-section { padding: 24px 20px; }
  .signature-grid { grid-template-columns: 1fr; gap: 24px; }
  .sow-content .sow-meta { grid-template-columns: 1fr; }
  .header-tagline { display: none; }
  .signature-actions { flex-direction: column; }
  .btn-sign { width: 100%; justify-content: center; }

  .sow-content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}
