:root {
  --ink: #111315;
  --ink-soft: #39434a;
  --paper: #f8faf9;
  --panel: #ffffff;
  --line: #d9e1df;
  --bay: #0d4f68;
  --bay-deep: #082d3d;
  --green: #2e7364;
  --foam: #dfeee9;
  --orange: #e77a2f;
  --orange-soft: #fff0e6;
  --shadow: 0 18px 45px rgba(5, 22, 29, .18);
  --editor-width: 44%;
  --font-main: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-main);
  background:
    linear-gradient(180deg, rgba(2, 8, 12, .70), rgba(2, 8, 12, .92)),
    url("assets/atb-background.png") center / cover fixed;
  min-height: 100vh;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
select,
input,
textarea {
  border: 1px solid var(--line);
}

button {
  min-height: 38px;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 13px;
  cursor: pointer;
  font-weight: 650;
}

button:hover {
  border-color: var(--bay);
}

button.primary {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
}

.export-link {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 9px 13px;
  text-decoration: none;
  font-weight: 650;
}

.export-link:hover {
  border-color: var(--bay);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 82px;
  padding: 16px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(4, 12, 16, .82);
  border-bottom: 1px solid rgba(255, 255, 255, .12);
  backdrop-filter: blur(14px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 270px;
}

.brand-logo {
  width: 96px;
  height: 40px;
  object-fit: contain;
}

.eyebrow,
.section-kicker {
  margin: 0 0 2px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 11px;
  font-weight: 800;
  color: #9ec7ca;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1,
h2,
h3,
h4,
th,
.proposal-cover h2,
.proposal-section h3 {
  font-family: var(--font-main);
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  margin-bottom: 0;
  color: #fff;
  font-size: 22px;
  line-height: 1.1;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.top-actions select {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 10px;
  min-width: 210px;
  background: rgba(255, 255, 255, .96);
}

.top-actions input {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 10px;
  width: 190px;
  background: rgba(255, 255, 255, .96);
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(360px, var(--editor-width)) 10px minmax(420px, 1fr);
  overflow: hidden;
}

.editor-pane,
.preview-pane {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.editor-pane {
  background: rgba(242, 247, 245, .96);
}

.editor-scroll {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.splitter {
  cursor: col-resize;
  background: linear-gradient(90deg, rgba(255,255,255,.12), rgba(255,255,255,.42), rgba(255,255,255,.12));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 22px rgba(13, 79, 104, .08);
}

.hero-panel {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  background: linear-gradient(135deg, #0a3a4f, #1d675e);
  color: #fff;
  border-color: rgba(255,255,255,.18);
}

.hero-panel h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.status-pill {
  flex: 0 0 auto;
  color: #fff;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

.field-grid label {
  margin-bottom: 0;
}

label span,
th {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

input,
textarea,
select {
  width: 100%;
  border-radius: 6px;
  background: #fbfdfc;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
  min-height: 92px;
  line-height: 1.45;
}

input:focus,
textarea:focus,
select:focus,
button:focus-visible,
.splitter:focus-visible {
  outline: 3px solid rgba(231, 122, 47, .24);
  border-color: var(--orange);
}

.section-head,
.budget-title-row,
.subtotal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-head {
  margin-bottom: 14px;
}

.section-head h3,
.budget-title-row h4 {
  margin: 0;
}

.budget-editor {
  display: grid;
  gap: 16px;
}

.budget-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fbfdfc;
}

.budget-title-row {
  padding: 10px 12px;
  background: #eef6f4;
}

.budget-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.budget-title-row button,
.budget-actions button {
  min-height: 32px;
  padding: 0 10px;
}

.budget-table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.budget-table {
  table-layout: fixed;
  min-width: max-content;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 7px;
  text-align: left;
  vertical-align: middle;
}

.budget-table th {
  position: relative;
  background: #edf5f2;
  padding-right: 12px;
}

.budget-table th.action-header,
.budget-table td.action-cell {
  width: 42px;
  min-width: 42px;
  text-align: center;
}

.column-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.column-head span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.column-head input {
  min-width: 58px;
  padding: 5px 6px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.remove-column {
  flex: 0 0 auto;
  width: 26px;
  min-height: 26px;
  padding: 0;
  color: #8a2f1a;
  background: var(--orange-soft);
  border-color: #ffd3bb;
}

.column-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 2;
}

.column-resizer::after {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 3px;
  width: 1px;
  background: rgba(13, 79, 104, .35);
}

.is-resizing-column {
  cursor: col-resize;
  user-select: none;
}

td input {
  min-width: 72px;
  padding: 7px 8px;
  background: #fff;
}

.row-total {
  font-weight: 800;
  white-space: nowrap;
}

.number-cell,
.money-cell,
.total-cell {
  text-align: right;
}

.remove-row {
  width: 34px;
  min-height: 32px;
  padding: 0;
  color: #8a2f1a;
  background: var(--orange-soft);
  border-color: #ffd3bb;
}

.subtotal-row {
  padding: 11px 12px;
  background: #fff;
}

.preview-pane {
  padding: 28px;
  background: rgba(10, 24, 29, .58);
}

.proposal-page {
  width: min(100%, 940px);
  min-height: calc(100vh - 140px);
  margin: 0 auto;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.proposal-cover {
  position: relative;
  min-height: 300px;
  padding: 34px 40px;
  color: #fff;
  background:
    linear-gradient(90deg, rgba(3, 12, 16, .92), rgba(3, 22, 28, .62), rgba(3, 12, 16, .35)),
    url("assets/atb-background.png") center / cover;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.proposal-cover img {
  width: 138px;
  height: auto;
}

.proposal-cover h2 {
  max-width: 680px;
  margin: 28px 0 10px;
  font-size: 42px;
  line-height: 1.03;
}

.proposal-cover p {
  margin-bottom: 0;
  color: #d9efef;
  font-size: 17px;
}

.proposal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.proposal-meta span {
  border: 1px solid rgba(255,255,255,.24);
  background: rgba(0,0,0,.22);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.proposal-body {
  padding: 34px 40px 42px;
}

.proposal-section {
  padding: 22px 0;
  border-bottom: 1px solid #dce4e3;
}

.proposal-section:first-child {
  padding-top: 0;
}

.proposal-section h3 {
  margin: 0 0 10px;
  color: var(--bay-deep);
  font-size: 18px;
}

.proposal-section p,
.proposal-section li {
  color: #273237;
  line-height: 1.55;
}

.proposal-section p {
  white-space: pre-line;
  margin-bottom: 0;
}

.two-column {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.preview-budget table {
  table-layout: fixed;
  min-width: max-content;
  background: #fff;
  border: 1px solid #dce4e3;
  margin-top: 10px;
}

.preview-budget {
  overflow-x: auto;
}

.preview-budget th {
  background: #edf5f2;
}

.preview-budget .number-cell,
.preview-budget .money-cell,
.preview-budget .total-cell {
  text-align: right;
}

.preview-subtotal,
.preview-grand {
  display: flex;
  justify-content: space-between;
  padding: 9px 0 0;
  font-weight: 800;
}

.preview-grand {
  margin-top: 14px;
  padding: 14px 16px;
  color: #fff;
  background: var(--bay-deep);
  border-left: 5px solid var(--orange);
}

.signature-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
  margin-top: 18px;
}

.signature-line {
  border-top: 1px solid #879594;
  padding-top: 8px;
  min-height: 44px;
  color: #4d5b5d;
  font-size: 13px;
}

.muted {
  color: #667579;
}

.export-body {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(2, 8, 12, .82), rgba(2, 8, 12, .94)),
    url("assets/atb-background.png") center / cover fixed;
}

.export-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 76px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(4, 12, 16, .88);
  border-bottom: 1px solid rgba(255, 255, 255, .14);
  backdrop-filter: blur(14px);
}

.export-toolbar h1 {
  margin-bottom: 0;
  color: #fff;
  font-size: 22px;
}

.export-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.export-stage {
  padding: 24px;
}

.export-stage .proposal-page {
  min-height: auto;
}

.export-note {
  width: min(100%, 940px);
  margin: 0 auto 14px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  color: #d9efef;
  background: rgba(0, 0, 0, .24);
  font-size: 13px;
  line-height: 1.35;
}

.export-status {
  width: min(100%, 940px);
  margin: -4px auto 14px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .workspace {
    display: block;
    overflow: auto;
  }

  .editor-pane,
  .preview-pane {
    overflow: visible;
  }

  .splitter {
    display: none;
  }

  .preview-pane {
    padding: 18px;
  }

  .field-grid,
  .two-column,
  .signature-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .top-actions,
  .top-actions select,
  .top-actions input,
  .top-actions button {
    width: 100%;
  }

  .editor-scroll,
  .preview-pane {
    padding: 12px;
  }

  .proposal-cover,
  .proposal-body {
    padding: 24px;
  }

  .proposal-cover h2 {
    font-size: 32px;
  }

  .export-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .export-actions,
  .export-actions a,
  .export-actions button {
    width: 100%;
  }
}

@media print {
  @page {
    size: letter;
    margin: 0.35in;
  }

  html,
  body,
  body.export-body {
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }

  * {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .topbar,
  .editor-pane,
  .splitter,
  .export-toolbar,
  .export-note,
  .export-status {
    display: none !important;
  }

  .workspace,
  .preview-pane,
  .export-stage {
    display: block;
    width: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }

  .proposal-page {
    display: block !important;
    width: 100% !important;
    min-height: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    box-shadow: none !important;
    background: #f8faf9 !important;
    border-top: 8px solid #0d4f68 !important;
  }

  .proposal-cover {
    min-height: 240px !important;
    padding: 28px 32px !important;
    color: #fff !important;
    background:
      linear-gradient(135deg, #071013 0%, #082d3d 44%, #2e7364 100%) !important;
    border-bottom: 6px solid #e77a2f !important;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .proposal-cover h2 {
    color: #fff !important;
  }

  .proposal-cover p {
    color: #d9efef !important;
  }

  .proposal-meta span {
    color: #fff !important;
    background: rgba(0, 0, 0, .28) !important;
    border-color: rgba(255, 255, 255, .34) !important;
  }

  .proposal-body {
    padding: 28px 32px 34px !important;
  }

  .proposal-section {
    border-bottom: 1px solid #cbd9d6 !important;
  }

  .proposal-section h3 {
    color: #082d3d !important;
    border-left: 5px solid #e77a2f !important;
    padding-left: 10px !important;
  }

  .proposal-section p,
  .proposal-section li {
    color: #111315 !important;
  }

  .preview-budget {
    overflow: visible !important;
  }

  .preview-budget table {
    width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed !important;
    border: 1px solid #9eb8b4 !important;
    background: #fff !important;
  }

  .preview-budget h4 {
    color: #0d4f68 !important;
  }

  .preview-budget th {
    color: #fff !important;
    background: #0d4f68 !important;
    border-bottom-color: #082d3d !important;
  }

  .preview-budget td {
    color: #111315 !important;
    border-bottom-color: #cbd9d6 !important;
  }

  .preview-subtotal {
    color: #082d3d !important;
  }

  .preview-grand {
    color: #fff !important;
    background: #082d3d !important;
    border-left-color: #e77a2f !important;
  }

  .proposal-section {
    break-inside: avoid;
  }

  .signature-line {
    color: #111315 !important;
    border-top-color: #2e7364 !important;
  }
}
