/* ============================
   GLOBAL BASE STYLES
   ============================ */

* {
  box-sizing: border-box;
}

:root {
  /* arxcafe palette tokens */
  --color-primary: #4A342E;
  --color-accent: #C6A992;
  --color-background: #F5F3F1;
  --color-surface: #FFFFFF;
  --color-text: #2B2B2B;
  --color-muted: #7A7A7A;
  --color-border: rgba(43, 43, 43, 0.14);

  /* Legacy aliases (avoid touching every selector) */
  --color-warm-red: var(--color-primary);
  --color-spring-green: var(--color-accent);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text);
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text);
}

h2 {
  margin: 20px 0 12px;
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
}

h2:first-child {
  margin-top: 0;
}

h3 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 700;
}

h4 {
  margin: 8px 0 6px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

p {
  margin: 0 0 6px;
}

ul {
  margin: 0 0 6px;
  padding-left: 16px;
}

li {
  margin-bottom: 3px;
  line-height: 1.45;
}

/* ============================
   PDF LAYOUT STYLES (GLOBAL)
   ============================ */

.pdf-document,
.proposal-document {
  /* Match app UI: clean, modern, highly readable */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 12px;
  line-height: 1.5;
  color: var(--color-text);
  position: relative;
  /* CRITICAL html2canvas fix: allow glyph overhang, add tiny gutter */
  box-sizing: content-box !important;
  width: calc(100% - 2px);
}

.pdf-document h3,
.proposal-document h3 {
  font-size: 18px;
  font-weight: 700;
  margin: 12px 0 8px;
}

.pdf-document h4,
.proposal-document h4 {
  font-size: 12px;
  font-weight: 700;
  margin: 10px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.01em;
}

.pdf-document p,
.proposal-document p {
  margin: 0 0 8px;
  line-height: 1.5;
  overflow: visible;
}

.pdf-document ul,
.proposal-document ul {
  margin: 0 0 8px 18px;
  padding: 0;
  list-style: disc;
}

.pdf-document li,
.proposal-document li {
  margin: 4px 0;
  line-height: 1.5;
  overflow: visible;
}

.pdf-document .executive-overview,
.proposal-document .executive-overview {
  background: rgba(198, 169, 146, 0.12);
  /* light accent tint */
  padding: 10px;
  margin: 0 0 12px;
  border-radius: 0;
  page-break-inside: avoid;
}

.pdf-document .executive-overview ul,
.proposal-document .executive-overview ul {
  margin: 0 0 0 18px;
}

.pdf-document .executive-overview li,
.proposal-document .executive-overview li {
  margin: 3px 0;
  font-size: 11px;
}

.pdf-document .section,
.proposal-document .section {
  page-break-inside: avoid;
  margin-bottom: 14px;
}

.hld-diagram {
  font-family: Consolas, "Courier New", monospace;
  font-size: 10px;
  line-height: 1.2;
  white-space: pre;
  background: var(--color-background);
  border: 1px solid var(--color-border);
  padding: 8px 10px;
  overflow-x: auto;
  display: block;
  max-width: 100%;
  box-sizing: border-box;
}

.gantt-chart {
  font-family: Consolas, "Courier New", monospace;
  font-size: 10px;
  line-height: 1.3;
  white-space: pre;
  background: var(--color-background);
  border: 1px solid var(--color-border);
  padding: 8px 10px;
  overflow-x: auto;
  display: block;
  max-width: 100%;
  box-sizing: border-box;
}

.pdf-document .title-page,
.proposal-document .title-page {
  text-align: center;
  padding: 40px 20px;
  page-break-after: always;
  page-break-inside: avoid;
  margin-bottom: 20px;
}

.proposal-title {
  font-size: 28px;
  margin: 0 0 16px;
  font-weight: 700;
  color: var(--color-warm-red);
}

.proposal-logo {
  max-width: 140px;
  height: auto;
  margin-bottom: 16px;
}

.proposal-client {
  font-size: 20px;
  margin: 0 0 8px;
  font-weight: 700;
}

.proposal-project {
  font-size: 14px;
  margin: 0 0 30px;
  color: var(--color-muted);
}

.proposal-meta {
  margin-top: 40px;
  font-size: 11px;
  color: var(--color-muted);
}

.proposal-meta p {
  margin: 3px 0;
}

.subtitle {
  font-size: 13px;
  color: var(--color-text);
  margin: 0 0 12px;
}

.proposal-footer {
  margin-top: 24px;
  padding-top: 8px;
  border-top: 1px solid var(--color-border);
  font-size: 10px;
  color: var(--color-muted);
}

.proposal-footer-inner {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.proposal-footer-credit {
  margin-top: 2px;
  text-align: right;
  font-size: 9px;
  color: var(--color-muted);
}

.proposal-footer-logo {
  max-width: 80px;
  height: auto;
}

.proposal-footer-brand {
  font-weight: 700;
  color: var(--color-warm-red);
}

.proposal-footer-text {
  white-space: nowrap;
  color: inherit;
}

.proposal-footer-sat {
  color: var(--color-spring-green);
}

.page-break {
  page-break-before: auto;
  height: 0;
  margin: 0;
  padding: 0;
  clear: both;
}

@media print {
  .hide-in-pdf {
    display: none !important;
  }

  /* In PDF/print, rely on styled text instead of the
     image to avoid any broken-logo placeholders. */
  .proposal-footer-logo {
    display: none !important;
  }

  .proposal-footer-brand {
    display: inline;
  }
}

/* ============================
   SCREEN UI ONLY (@media screen)
   ============================ */

@media screen {

  html,
  body {
    background: var(--color-background);
    overflow-x: hidden;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  }

  .topbar h1 {
    color: var(--color-spring-green);
  }

  .topbar-buttons {
    display: flex;
    gap: 12px;
    align-items: center;
  }

  .layout {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 16px;
    padding: 16px;
    max-width: 1600px;
    margin: 0 auto;
  }

  .panel {
    background: var(--color-surface);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }

  .btn {
    padding: 7px 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    font-family: inherit;
    font-size: 10px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: all 0.2s;
  }

  .btn:hover {
    background: var(--color-background);
    border-color: var(--color-border);
  }

  .btn.primary {
    background: var(--color-primary);
    color: var(--color-surface);
    border-color: var(--color-primary);
    font-weight: 600;
  }

  .btn.primary:hover {
    filter: brightness(0.92);
  }

  .btn.danger {
    background: #dc3545;
    color: var(--color-surface);
    border-color: #dc3545;
    font-weight: 600;
  }

  .btn.danger:hover {
    background: #c82333;
    border-color: #c82333;
  }

  .form {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .form label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 4px;
  }

  .form input,
  .form textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    background: var(--color-surface);
    transition: all 0.2s;
  }

  .form input:focus,
  .form textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-border);
  }

  .form button {
    width: 100%;
    margin-top: 8px;
  }

  .generate-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
  }

  .generate-row .btn {
    flex: 0 0 auto;
    max-width: 48%;
    white-space: nowrap;
  }

  .loading-indicator {
    display: none;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #0a8f54;
  }

  .loading-indicator.active {
    display: inline-flex;
  }

  .loading-spinner {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(10, 143, 84, 0.2);
    border-top-color: #0a8f54;
    animation: spin 0.8s linear infinite;
  }

  @keyframes spin {
    to {
      transform: rotate(360deg);
    }
  }

  .list {
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .list li {
    padding: 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    background: var(--color-surface);
    font-size: 13px;
    transition: all 0.2s;
  }

  .list li:hover {
    background: var(--color-background);
    border-color: var(--color-border);
  }

  .list li.active {
    border-color: var(--color-primary);
    background: rgba(198, 169, 146, 0.18);
    color: var(--color-primary);
    font-weight: 500;
  }

  .list li.user-edited {
    border-color: #ff9800;
    background: #fff3cd;
    color: #8a5a00;
  }

  .list li.user-edited.active {
    border-color: #fb8c00;
    background: #ffe8a1;
    color: #8a5a00;
    font-weight: 600;
  }

  .list li.sent-to-management {
    border-color: #1b7f3b;
    background: #e3f6eb;
    color: #1b7f3b;
  }

  .list li.sent-to-management.active {
    border-color: #0f5a29;
    background: #d1f0df;
    color: #0f5a29;
    font-weight: 600;
  }

  /* When a proposal is both edited and sent, show half orange / half green */
  .list li.user-edited.sent-to-management,
  .list li.user-edited.sent-to-management.active {
    border-color: #1b7f3b;
    background: linear-gradient(90deg, #fff3cd 0%, #fff3cd 50%, #e3f6eb 50%, #e3f6eb 100%);
    color: #2d4b1f;
    font-weight: 600;
  }

  .proposal {
    min-height: 420px;
  }

  .placeholder {
    color: var(--color-muted);
    padding: 16px;
    border: 1px dashed var(--color-border);
    border-radius: 10px;
    background: var(--color-surface);
    font-size: 13px;
  }

  .edit-panel {
    margin-top: 8px;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .edit-panel label {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text);
    display: block;
  }

  .edit-panel textarea {
    width: 100%;
    margin-top: 4px;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: inherit;
    font-size: 12px;
    resize: none;
    overflow: hidden;
  }

  .snapshot-privacy-wrapper {
    margin-top: 4px;
  }

  .snapshot-privacy-wrapper.blurred {
    filter: blur(5px);
  }

  .snapshot-privacy-note {
    font-size: 10px;
    color: var(--color-muted);
    margin-top: 4px;
  }

  form label {
    display: block;
    margin-bottom: 12px;
    font-size: 12px;
    font-weight: 600;
  }

  form input,
  form textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 11px;
    margin-top: 4px;
  }

  form input:focus,
  form textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-border);
  }
}

/* Firm Offer specific styling */
.firm-offer-list {
  list-style-type: disc;
  padding-left: 20px;
  margin: 8px 0;
}

.firm-offer-list li {
  margin-bottom: 6px;
  line-height: 1.6;
}

.pricing-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-family: Arial, sans-serif;
  font-size: 13px;
}

.pricing-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  line-height: 1.5;
}

.pricing-table tr:last-child td {
  border-bottom: 2px solid var(--color-text);
}

/* Simple effort breakdown table (used under Risk Assessment and Effort sections) */
.effort-table-wrapper {
  page-break-before: always;
}

.effort-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 0;
  font-size: 11px;
  page-break-inside: avoid;
  break-inside: avoid;
}

.effort-table th,
.effort-table td {
  padding: 6px 8px;
  border: 1px solid var(--color-text);
  /* darker for clear PDF grid lines */
}

.effort-table th {
  background: rgba(198, 169, 146, 0.12);
  text-align: left;
  font-weight: 600;
}

.effort-hours {
  text-align: right;
  white-space: nowrap;
}

/* Simple two-column tables for assumptions/dependencies/out-of-scope/contract terms */
.simple-section-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 11px;
}

.simple-section-table th,
.simple-section-table td {
  padding: 4px 6px;
  border: 1px solid var(--color-text);
  /* darker for clear PDF grid lines */
}

.simple-section-table th {
  background: rgba(198, 169, 146, 0.12);
  text-align: left;
  font-weight: 600;
}

.highlight-box {
  background: rgba(198, 169, 146, 0.12);
  border-left: 4px solid var(--color-warm-red);
  padding: 12px 16px;
  margin: 8px 0;
  border-radius: 4px;
}

.highlight-box p {
  margin: 0;
}

.proposal-document {
  counter-reset: section;
}

.proposal-document .section h2 {
  margin-top: 24px;
  margin-bottom: 12px;
  color: var(--color-text);
  border-bottom: 2px solid var(--color-warm-red);
  padding-bottom: 8px;
}

/* Responsibility matrix table */
.responsibility-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 16px;
  font-size: 11px;
}

.responsibility-table th,
.responsibility-table td {
  padding: 6px 8px;
  border: 1px solid var(--color-text);
  /* darker for clear PDF grid lines */
}

.responsibility-table th {
  background: rgba(198, 169, 146, 0.12);
  color: var(--color-text);
  text-align: left;
  font-weight: 600;
}

.responsibility-table th.client-col,
.responsibility-table td.client-col {
  background: var(--color-warm-red);
  color: var(--color-surface);
}

.responsibility-table th.provider-col,
.responsibility-table td.provider-col {
  background: var(--color-spring-green);
  color: var(--color-text);
}

.responsibility-table tbody tr:nth-child(even) td {
  background: rgba(198, 169, 146, 0.16);
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  body {
    background: var(--color-surface);
    margin: 0;
  }

  .topbar,
  .panel:first-child,
  #deleteBtn,
  #pdfBtn {
    display: none !important;
  }

  .layout {
    display: block;
    padding: 0;
    gap: 0;
    grid-template-columns: none;
  }

  .panel {
    border: none;
    padding: 0;
    border-radius: 0;
  }

  .proposal {
    min-height: auto;
  }

  .proposal-document {
    padding: 0;
    width: auto;
  }

  /* Force strong table grid lines in PDF output */
  .effort-table,
  .effort-table th,
  .effort-table td,
  .simple-section-table,
  .simple-section-table th,
  .simple-section-table td,
  .responsibility-table,
  .responsibility-table th,
  .responsibility-table td {
    border: 0.75pt solid var(--color-text) !important;
    border-collapse: collapse !important;
    border-spacing: 0 !important;
  }
}

/* Firm-offer document width constraint for PDF clone only is applied via JS; no width limit on-screen */