/* ==========================================================================
   HI TECH & MARKETING - DIGITAL AGREEMENT PORTAL STYLESHEET
   Design System: Clean, Professional White Theme (Matching PDF exactly)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@600;700&family=Dancing+Script:wght@700&display=swap');

:root {
  /* Brand Color Palette */
  --color-brand-primary: #1e5b99;
  --color-brand-hover: #154577;
  
  /* Light Theme Surfaces */
  --bg-app: #f8f9fa;
  --bg-surface: #ffffff;
  
  /* Text Colors */
  --text-main: #000000;
  --text-muted: #333333;
  --text-faint: #666666;

  /* Borders & Shadows */
  --border-subtle: #dee2e6;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.1);

  /* Typography */
  --font-sans: Arial, Helvetica, sans-serif;
  --font-signature: 'Caveat', cursive;

  /* Layout */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --transition-fast: 0.2s ease;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   NAVIGATION BAR
   ========================================================================== */
.portal-navbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow-card);
}

.nav-container {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-main);
}

.brand-badge-logo {
  height: 40px;
  width: auto;
}

.brand-title-wrap {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-weight: 700;
  font-size: 1.1rem;
}

.brand-subtitle {
  font-size: 0.8rem;
  color: var(--text-faint);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.view-toggle-pill {
  display: flex;
  background: #f1f3f5;
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: bold;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.toggle-btn.active {
  background: #ffffff;
  color: var(--color-brand-primary);
  box-shadow: var(--shadow-card);
}

/* ==========================================================================
   APP MAIN CONTAINER
   ========================================================================== */
.app-viewport {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2rem 1.5rem 5rem;
}

/* ==========================================================================
   ADMIN DASHBOARD VIEW
   ========================================================================== */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.dash-title-group h1 {
  font-size: 1.8rem;
  font-weight: bold;
  margin-bottom: 0.25rem;
}

.dash-title-group p {
  color: var(--text-faint);
  font-size: 0.95rem;
}

.dash-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Buttons */
.btn-primary {
  background: var(--color-brand-primary);
  color: #ffffff;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition-fast);
  text-decoration: none;
}

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

.btn-secondary {
  background: #ffffff;
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition-fast);
}

.btn-secondary:hover {
  background: #f8f9fa;
  border-color: #adb5bd;
}

/* Metric Cards Grid */
.stats-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2.5rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.2rem;
  box-shadow: var(--shadow-card);
}

.stat-icon-wrap {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
  background: #f1f3f5;
}

.stat-meta {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: bold;
  line-height: 1.1;
}

.stat-label {
  font-size: 0.9rem;
  color: var(--text-faint);
}

/* Agreements Table Container */
.agreements-table-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.table-title {
  font-size: 1.2rem;
  font-weight: bold;
}

.search-box {
  position: relative;
  min-width: 260px;
}

.search-box input {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem 0.5rem 2.2rem;
  font-size: 0.9rem;
  outline: none;
}

.search-box .search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
}

/* Table Design */
.data-table-wrapper {
  overflow-x: auto;
}

.portal-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.portal-table th {
  background: #f8f9fa;
  padding: 0.9rem 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: bold;
  border-bottom: 2px solid var(--border-subtle);
}

.portal-table td {
  padding: 1rem 1.25rem;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.doc-code {
  font-family: monospace;
  font-weight: bold;
  color: var(--color-brand-primary);
}

.doc-title {
  display: block;
  color: var(--text-faint);
  font-size: 0.8rem;
}

.client-meta-cell strong {
  display: block;
  font-size: 0.95rem;
}

.client-meta-cell small {
  color: var(--text-faint);
  font-size: 0.85rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: bold;
}

.badge-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.badge-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }

.action-btn-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-action-icon {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.btn-action-icon:hover {
  background: #f8f9fa;
  color: var(--text-main);
}

/* ==========================================================================
   CLIENT VIEW / FORMAL CONTRACT SHEET
   ========================================================================== */
.client-view-container {
  max-width: 850px;
  margin: 0 auto;
}

.client-view-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.signed-success-banner {
  background: #d4edda;
  border: 1px solid #c3e6cb;
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  color: #155724;
}

/* ==========================================================================
   FORMAL PRINTABLE / EXPORTABLE CONTRACT PAPER (EXACTLY MATCHING PDF)
   ========================================================================== */
.contract-paper {
  background: #ffffff;
  color: #000000;
  border: 1px solid var(--border-subtle);
  padding: 3rem 4rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 2rem;
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.4;
}

/* Header with Brand Logo */
.contract-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.contract-logo-img {
  max-width: 200px;
  height: auto;
  margin: 0 auto 1rem;
  display: block;
}

.contract-main-title {
  font-size: 1.4rem;
  font-weight: bold;
  text-transform: uppercase;
  margin-bottom: 1.5rem;
}

/* Provider & Client Info Grid */
.contract-parties-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.party-info-list {
  list-style: none;
}

.party-info-list li {
  margin-bottom: 0.3rem;
}

/* Services Included Section */
.contract-section {
  margin-bottom: 1.5rem;
  page-break-inside: avoid;
  break-inside: avoid;
}

.contract-section-heading {
  font-size: 1.2rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.services-grid-layout {
  display: block;
}

.service-category-block {
  margin-bottom: 0.8rem;
}

.service-category-block .category-heading {
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 0.2rem;
}

.service-items-list {
  list-style: none;
  font-size: 0.95rem;
}

.service-items-list li {
  position: relative;
  margin-bottom: 0.2rem;
}

/* Payment Terms Section */
.payment-terms-box {
  margin-bottom: 1.5rem;
  page-break-inside: avoid;
  break-inside: avoid;
}

.payment-terms-list {
  list-style: none;
  font-size: 0.95rem;
}

.payment-terms-list li {
  position: relative;
  margin-bottom: 0.3rem;
}

.pricing-summary-card {
  display: none; /* Hide for exact PDF match unless needed */
}

/* Signatures Table Section (Modeled exactly off the PDF's 2-column table) */
.signatures-table-section {
  margin-top: 2rem;
  border: 1px solid #c2c2c2;
  border-collapse: collapse;
  width: 100%;
  page-break-inside: avoid;
  break-inside: avoid;
}

.sig-table-header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #1e5b99; /* Exact royal blue bar from user's PDF */
  color: #ffffff;
}

.sig-table-header > div {
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
}

.sig-table-header > div:first-child {
  border-right: 1px solid #c2c2c2;
}

.sig-table-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #eef0c6; /* Exact soft yellow signature background from user's PDF */
}

.sig-column {
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.sig-column:first-child {
  border-right: 1px solid #c2c2c2;
}

.sig-row-item {
  margin-bottom: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.signature-display-box {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.signature-image {
  max-height: 40px;
  width: auto;
  object-fit: contain;
  margin-left: 0.5rem;
}

.signature-line {
  display: inline-block;
  border-bottom: 1px solid #000;
  width: 200px;
  height: 20px;
}

.verified-signed-box {
  position: relative;
}

/* Official Document Security Footer */
.contract-footer-audit {
  display: none; /* Hide default audit footer to match PDF exactly */
}

/* ==========================================================================
   INTERACTIVE SIGNING STATION (UNDER CONTRACT)
   ========================================================================== */
.signing-station-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 2rem;
  box-shadow: var(--shadow-card);
}

.station-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.station-header h3 {
  font-size: 1.25rem;
  font-weight: bold;
}

.signing-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.9rem;
  font-weight: bold;
}

.form-control {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  font-size: 0.95rem;
  outline: none;
}

.form-control:focus {
  border-color: var(--color-brand-primary);
}

/* Signature Pad Toolbar */
.signature-pad-box {
  background: #f8f9fa;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.sig-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.sig-mode-btn {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
}

.sig-mode-btn.active {
  background: var(--color-brand-primary);
  color: #fff;
  border-color: var(--color-brand-primary);
}

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

.btn-sig-tool {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
}

/* Canvas Area */
.sig-canvas-area {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  height: 150px;
  cursor: crosshair;
}

#signature-canvas {
  width: 100%;
  height: 100%;
}

.typed-sig-controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.typed-sig-controls input, .typed-sig-controls select {
  padding: 0.5rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

/* Consent check */
.consent-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.btn-finalize-sign {
  width: 100%;
  background: #28a745;
  color: #ffffff;
  border: none;
  padding: 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
}

.btn-finalize-sign:hover {
  background: #218838;
}

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-overlay.active { display: flex; }

.modal-window {
  background: #ffffff;
  border-radius: var(--radius-md);
  width: 100%; max-width: 600px; max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-close-btn {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  background: transparent;
  border: none;
  font-size: 2rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  transition: color var(--transition-fast);
}

.modal-close-btn:hover {
  color: #dc3545;
}

.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal-form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
}
.full-span { grid-column: 1 / -1; }

.share-link-group {
  display: flex; gap: 0.5rem; margin: 1rem 0;
}
.share-link-group input { flex: 1; }

.btn-whatsapp-direct {
  background: #25d366; color: #fff; text-decoration: none;
  padding: 0.75rem 1rem; border-radius: var(--radius-sm);
  font-weight: bold; display: inline-flex; align-items: center; gap: 0.5rem;
}

/* ==========================================================================
   MOBILE RESPONSIVENESS
   ========================================================================== */
@media (max-width: 768px) {
  .app-viewport {
    padding: 1rem 0.75rem;
  }
  
  .contract-paper {
    padding: 1.5rem !important;
  }
  
  .contract-parties-grid,
  .signing-form-grid,
  .modal-form-grid {
    grid-template-columns: 1fr !important;
    gap: 1.5rem;
  }

  .sig-column {
    padding: 0.5rem;
  }
  .sig-table-header > div {
    padding: 0.5rem;
  }
  
  .sig-toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .sig-canvas-area {
    height: 120px;
  }

  .modal-body {
    padding: 1.5rem 1rem !important;
  }
  
  .contract-main-title {
    font-size: 1.1rem;
  }
}

/* ==========================================================================
   PDF EXPORT MODE (Triggered via JS for html2pdf)
   ========================================================================== */
.contract-paper.pdf-exporting {
  border: none !important;
  box-shadow: none !important;
  margin: 0 !important;
  border-radius: 0 !important;
  padding: 0 !important; /* Let jsPDF margin handle the whitespace */
  width: 100% !important;
  max-width: none !important;
}

/* ==========================================================================
   PRINT STYLESHEET (For exact PDF generation via browser print)
   ========================================================================== */
@media print {
  body {
    background: #ffffff !important;
    font-size: 11pt !important;
  }
  .portal-navbar, .client-view-top-bar, .signing-station-card,
  .signed-success-banner, .modal-overlay, #admin-view-section {
    display: none !important;
  }
  .app-viewport { padding: 0 !important; }
  .contract-paper {
    padding: 0 !important; border: none !important; box-shadow: none !important;
  }
  .sig-table-header {
    background-color: #1e5b99 !important; color: #ffffff !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .sig-table-body {
    background-color: #eef0c6 !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
