/* ==========================================================================
   SPA Calculator - Calculator-specific styles
   Scoped under .pw-spa-calc. Loaded after shared.css.
   ========================================================================== */

/* Layout
   ========================================================================== */

.pw-spa-calc {
  max-width: 700px;
  margin: 0 auto;
  padding: 24px 0;
}

/* Header
   ========================================================================== */

.pw-spa-calc .pw-spa-header {
  margin-bottom: 24px;
}

/* Language Toggle
   ========================================================================== */

.pw-spa-calc .pw-lang-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--pw-border);
  border-radius: var(--pw-radius-sm);
  overflow: hidden;
}

.pw-spa-calc .pw-lang-btn {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--pw-text-light);
  transition: all 0.2s;
}

.pw-spa-calc .pw-lang-btn.pw-lang-active {
  background: var(--pw-primary);
  color: #fff;
}

/* Tier Table Rows
   ========================================================================== */

/* Force flex row layout — !important needed to override Divi 5 inherited styles */
.pw-spa-calc .pw-tier-row {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

/* Column header row — must match exact same flex proportions as data rows */
.pw-spa-calc .pw-tier-header-row {
  margin-bottom: 2px;
  align-items: flex-end;
}

.pw-spa-calc .pw-tier-header-row .pw-tier-actions {
  /* Match width of 3 buttons (28px each) + 2 gaps (4px each) */
  min-width: 92px;
}

.pw-spa-calc .pw-tier-col-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--pw-text-light);
  line-height: 1.3;
  white-space: nowrap;
}

/* Override shared.css width:100% — inputs inside tier rows must respect flex sizing */
.pw-spa-calc .pw-tier-row .pw-input-threshold,
.pw-spa-calc .pw-tier-row span.pw-input-threshold {
  flex: 3 1 0% !important;
  width: auto !important;
  min-width: 0;
  max-width: none;
}

.pw-spa-calc .pw-tier-row .pw-input-rate,
.pw-spa-calc .pw-tier-row span.pw-input-rate {
  flex: 1 1 0% !important;
  width: auto !important;
  min-width: 55px;
  max-width: none;
}

.pw-spa-calc .pw-tier-actions {
  display: flex !important;
  flex-direction: row !important;
  gap: 4px;
  flex-shrink: 0;
}

/* Action buttons — clean chevron/trash style */
.pw-spa-calc .pw-tier-action-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: var(--pw-radius-sm);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #374151;
  transition: all 0.15s;
}

.pw-spa-calc .pw-tier-action-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pw-spa-calc .pw-tier-action-btn:hover {
  background: #f3f4f6;
  color: #111827;
}

.pw-spa-calc .pw-tier-action-btn.pw-tier-delete {
  color: var(--pw-danger);
}

.pw-spa-calc .pw-tier-action-btn.pw-tier-delete:hover {
  background: #fef2f2;
}

/* Disabled state for boundary buttons */
.pw-spa-calc .pw-tier-action-btn.pw-disabled {
  color: #d1d5db;
  cursor: default;
  pointer-events: none;
}

/* Disabled threshold for "No limit" row */
.pw-spa-calc .pw-input-threshold:disabled {
  background: #f9fafb;
  color: var(--pw-text-light);
}

/* Tier Range Summary Box
   ========================================================================== */

.pw-spa-calc .pw-tier-summary {
  margin-top: 8px;
  padding: 8px 12px;
  background: #f9fafb;
  border: 1px solid #f3f4f6;
  border-radius: var(--pw-radius-sm);
  font-size: 12px;
  color: var(--pw-text-light);
  line-height: 1.6;
}

.pw-spa-calc .pw-tier-summary-line {
  display: flex;
  justify-content: space-between;
}

.pw-spa-calc .pw-tier-summary-rate {
  font-weight: 500;
  color: var(--pw-text);
}

/* Loan Percentage Slider
   ========================================================================== */

.pw-spa-calc .pw-loan-pct-display {
  font-size: 18px;
  font-weight: 600;
  color: var(--pw-primary);
}

/* Section Toggle (show/hide areas)
   ========================================================================== */

.pw-spa-calc .pw-loan-section,
.pw-spa-calc .pw-stamp-mot-section,
.pw-spa-calc .pw-stamp-loan-section,
.pw-spa-calc .pw-sst-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--pw-border);
}

/* Actions Bar
   ========================================================================== */

.pw-spa-calc .pw-actions {
  margin-bottom: 16px;
}

/* Results Card
   ========================================================================== */

.pw-spa-calc .pw-results-card {
  border: 2px solid var(--pw-border);
}

/* Results table */
.pw-spa-calc .pw-results-section {
  margin-bottom: 20px;
}

.pw-spa-calc .pw-results-section-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--pw-text-light);
  margin-bottom: 8px;
}

.pw-spa-calc .pw-results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.pw-spa-calc .pw-results-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--pw-text-light);
  padding: 4px 8px 4px 0;
  border-bottom: 1px solid var(--pw-border);
}

.pw-spa-calc .pw-results-table td {
  padding: 6px 8px 6px 0;
  border-bottom: 1px solid #f3f4f6;
}

.pw-spa-calc .pw-results-table .pw-text-right {
  text-align: right;
}

.pw-spa-calc .pw-results-table .pw-subtotal-row td {
  font-weight: 600;
  border-top: 1px solid var(--pw-border);
  border-bottom: none;
  padding-top: 8px;
}

/* Summary section */
.pw-spa-calc .pw-summary-divider {
  border: none;
  border-top: 1px solid var(--pw-border);
  margin: 16px 0;
}

.pw-spa-calc .pw-summary-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
}

.pw-spa-calc .pw-total-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0 4px;
  font-size: 18px;
  font-weight: 700;
}

.pw-spa-calc .pw-total-amount {
  color: var(--pw-primary);
}

.pw-spa-calc .pw-total-note {
  font-size: 13px;
  color: var(--pw-text-light);
  text-align: right;
  margin-top: 4px;
}

/* Results action buttons */
.pw-spa-calc .pw-results-actions {
  display: flex;
  gap: 8px;
}

/* Copy button success state */
.pw-spa-calc .pw-copy-btn.pw-copied {
  color: var(--pw-success);
  border-color: var(--pw-success);
}

/* Disbursement Items
   ========================================================================== */

.pw-spa-calc .pw-disbursement-item-row {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.pw-spa-calc .pw-disbursement-item-row .pw-input-item-name {
  flex: 2 1 0% !important;
  width: auto !important;
}

.pw-spa-calc .pw-disbursement-item-row .pw-input-item-amount {
  flex: 1 1 0% !important;
  width: auto !important;
}

/* Responsive (Mobile)
   ========================================================================== */

@media (max-width: 600px) {
  .pw-spa-calc {
    padding: 16px 12px;
  }

  .pw-spa-calc .pw-spa-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .pw-spa-calc .pw-card {
    padding: 16px;
  }

  .pw-spa-calc .pw-tier-row {
    gap: 4px;
  }

  .pw-spa-calc .pw-tier-row .pw-input-threshold,
  .pw-spa-calc .pw-tier-row span.pw-input-threshold {
    flex: 2 1 0% !important;
    width: auto !important;
    font-size: 14px;
    padding: 8px;
  }

  .pw-spa-calc .pw-tier-row .pw-input-rate,
  .pw-spa-calc .pw-tier-row span.pw-input-rate {
    flex: 0 0 50px !important;
    width: auto !important;
    font-size: 14px;
    padding: 8px;
  }

  .pw-spa-calc .pw-tier-actions {
    gap: 2px;
  }

  .pw-spa-calc .pw-tier-action-btn {
    width: 24px;
    height: 24px;
  }

  .pw-spa-calc .pw-tier-action-btn svg {
    width: 14px;
    height: 14px;
  }

  .pw-spa-calc .pw-tier-col-label {
    font-size: 11px;
  }

  .pw-spa-calc .pw-tier-header-row {
    gap: 4px;
  }

  .pw-spa-calc .pw-tier-header-row .pw-tier-actions {
    /* Match width of 3 mobile buttons (24px each) + 2 gaps (2px each) */
    min-width: 76px;
  }

  .pw-spa-calc .pw-results-table {
    font-size: 13px;
  }

  .pw-spa-calc .pw-total-row {
    font-size: 16px;
  }

  .pw-spa-calc .pw-summary-row {
    font-size: 13px;
  }
}

/* Print Overlay (hidden on screen, visible only when printing)
   ========================================================================== */

#pw-print-overlay {
  display: none;
}

@media print {
  /* Hide everything on the page */
  body > * {
    display: none !important;
  }

  /* Show only the print overlay */
  #pw-print-overlay {
    display: block !important;
    position: static;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #1f2937;
    font-size: 13px;
    line-height: 1.5;
    padding: 0;
  }

  @page {
    margin: 15mm;
  }

  .pw-print-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-bottom: 16px;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 24px;
  }

  .pw-print-logo {
    max-height: 48px;
    max-width: 120px;
    object-fit: contain;
  }

  .pw-print-site-name {
    font-size: 16px;
    font-weight: 700;
    color: #111827;
  }

  .pw-print-site-domain {
    font-size: 12px;
    color: #6b7280;
  }

  .pw-print-title {
    font-size: 16px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 16px;
  }

  .pw-print-meta {
    margin-bottom: 20px;
    font-size: 13px;
  }

  .pw-print-meta-row {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
  }

  .pw-print-meta-label {
    font-weight: 600;
    min-width: 140px;
  }

  .pw-print-section-title {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin: 20px 0 8px;
  }

  .pw-print-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-bottom: 16px;
  }

  .pw-print-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 500;
    color: #6b7280;
    padding: 4px 8px 4px 0;
    border-bottom: 1px solid #e5e7eb;
  }

  .pw-print-table td {
    padding: 5px 8px 5px 0;
    border-bottom: 1px solid #f3f4f6;
  }

  .pw-print-right {
    text-align: right;
  }

  .pw-print-subtotal td {
    font-weight: 600;
    border-top: 1px solid #d1d5db;
    border-bottom: none;
    padding-top: 8px;
  }

  .pw-print-divider {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 16px 0;
  }

  .pw-print-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 13px;
  }

  .pw-print-total-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0 4px;
    font-size: 16px;
    font-weight: 700;
    border-top: 2px solid #1f2937;
    margin-top: 8px;
  }

  .pw-print-total-amount {
    color: #2563eb;
  }

  .pw-print-footer {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
    font-size: 11px;
    color: #9ca3af;
  }

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