:root {
  --ink: #102133;
  --muted: #687786;
  --paper: #ffffff;
  --canvas: #eef2f5;
  --line: #dce4ea;
  --navy: #0d1b2a;
  --red: #d63c32;
  --blue: #245fa8;
  --gold: #b57a1f;
  --green: #2f7d5b;
  --shadow: 0 18px 50px rgba(16, 33, 51, 0.11);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  min-height: 76px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
.brand-wrap { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--red);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  transform: rotate(-3deg);
}
.brand-name, .print-brand { font-weight: 900; letter-spacing: -.04em; font-size: 23px; }
.brand-name span, .print-brand span { color: var(--red); }
.brand-subtitle { color: #aeb9c4; font-size: 12px; margin-top: 1px; }
.topbar-actions { display: flex; gap: 10px; }
.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 750;
}
.btn-primary { background: var(--red); color: #fff; }
.btn-ghost { background: rgba(255,255,255,.09); color: #fff; border: 1px solid rgba(255,255,255,.14); }

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(700px, 1fr);
  gap: 24px;
  padding: 24px;
  align-items: start;
}
.editor-panel, .preview-panel { min-width: 0; }
.editor-panel {
  background: var(--paper);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 100px;
  max-height: calc(100vh - 124px);
  overflow: auto;
}
.section-heading, .compact-heading, .settings-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 29px; letter-spacing: -.035em; }
.compact-heading h2 { margin-bottom: 0; font-size: 20px; }
.eyebrow { color: var(--red); font-size: 11px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 5px; }
.save-status { font-size: 12px; color: var(--green); font-weight: 750; background: #edf8f2; padding: 7px 9px; border-radius: 999px; }
.section-divider { height: 1px; background: var(--line); margin: 22px 0; }
.form-grid { display: grid; gap: 14px; margin-top: 22px; }
.two-col { grid-template-columns: 1fr 1fr; }
label { display: grid; gap: 6px; }
label > span, .field-title { font-size: 12px; color: var(--muted); font-weight: 750; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  color: var(--ink);
  background: #fff;
}
input:focus, textarea:focus { border-color: #89a7c3; box-shadow: 0 0 0 3px rgba(36,95,168,.09); }
textarea { resize: vertical; margin-top: 12px; }
.input-prefix, .input-suffix { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.input-prefix span, .input-suffix span { padding: 0 11px; color: var(--muted); font-size: 12px; font-weight: 800; white-space: nowrap; }
.input-prefix input, .input-suffix input { border: 0; border-radius: 0; box-shadow: none; padding-left: 0; }
.input-suffix input { padding-left: 12px; }
.checkbox-label { display: flex; align-items: center; align-self: end; min-height: 43px; gap: 9px; padding: 0 2px; }
.checkbox-label input { width: 18px; height: 18px; }
.checkbox-label span { color: var(--ink); }

.preview-panel { overflow: auto; }
.worksheet {
  width: min(100%, 1000px);
  min-height: 760px;
  margin: 0 auto;
  background: var(--paper);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 34px;
}
.worksheet-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; border-bottom: 2px solid var(--ink); padding-bottom: 18px; }
.print-brand { font-size: 31px; }
.worksheet-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .12em; font-weight: 800; }
.worksheet-meta { display: flex; gap: 26px; text-align: right; }
.worksheet-meta div { display: grid; gap: 3px; }
.worksheet-meta span, .customer-strip span, .deal-summary span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .09em; font-weight: 800; }
.worksheet-meta strong { font-size: 13px; }
.customer-strip { display: grid; grid-template-columns: 1.1fr 1.7fr .5fr; gap: 18px; padding: 18px 0; }
.customer-strip div { display: grid; gap: 5px; }
.customer-strip strong { font-size: 15px; }
.four-square-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.square-card { min-height: 242px; border: 1px solid var(--line); border-radius: 15px; padding: 20px; position: relative; overflow: hidden; }
.square-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: currentColor; }
.accent-blue { color: var(--blue); }
.accent-gold { color: var(--gold); }
.accent-red { color: var(--red); }
.accent-green { color: var(--green); }
.square-number { position: absolute; top: 14px; right: 16px; font-weight: 900; font-size: 28px; opacity: .10; }
.square-card > p { margin: 0 0 10px; text-transform: uppercase; letter-spacing: .11em; font-size: 11px; font-weight: 900; color: currentColor; }
.square-card h2 { font-size: 38px; letter-spacing: -.045em; color: var(--ink); margin: 0 0 18px; }
dl { margin: 0; color: var(--ink); }
dl div { display: flex; justify-content: space-between; gap: 15px; padding: 7px 0; font-size: 13px; }
dt { color: var(--muted); }
dd { margin: 0; font-weight: 850; }
.total-line { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 11px; }
.down-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 20px; }
.down-pill { border: 1px solid var(--line); border-radius: 12px; padding: 13px 8px; text-align: center; background: #fffafa; }
.down-pill span { display: block; font-size: 10px; text-transform: uppercase; color: var(--muted); font-weight: 800; margin-bottom: 4px; }
.down-pill strong { color: var(--ink); font-size: 18px; }
.mini-summary { margin-top: 18px; padding-top: 13px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; color: var(--ink); font-size: 13px; }
.payment-card { min-height: 242px; }
.payment-table-wrap { overflow: hidden; border: 1px solid var(--line); border-radius: 11px; margin-top: 14px; }
.payment-table { width: 100%; border-collapse: collapse; color: var(--ink); font-size: 12px; }
.payment-table th, .payment-table td { padding: 11px 8px; text-align: center; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); }
.payment-table th:last-child, .payment-table td:last-child { border-right: 0; }
.payment-table tr:last-child td { border-bottom: 0; }
.payment-table th { background: #f3f7f5; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.payment-table td:first-child { text-align: left; font-weight: 850; }
.payment-table strong { font-size: 14px; }
.deal-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 15px; }
.deal-summary div { background: #f7f9fb; border-radius: 11px; padding: 13px 14px; display: grid; gap: 5px; }
.deal-summary strong { font-size: 16px; }
.deal-note { text-align: center; font-style: italic; color: var(--muted); margin: 18px 0 0; min-height: 18px; }
.worksheet-footer { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 15px; }
.worksheet-footer p { color: var(--muted); font-size: 9px; line-height: 1.45; }
.signature-row { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 28px; }
.signature-row div { border-top: 1px solid var(--ink); padding-top: 6px; }
.signature-row span { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

#settingsDialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 30px 90px rgba(0,0,0,.3); }
#settingsDialog::backdrop { background: rgba(10,20,31,.65); backdrop-filter: blur(3px); }
.settings-card { padding: 24px; display: grid; gap: 20px; }
.settings-header h2 { margin: 0; }
.icon-btn { border: 0; background: #eef2f5; color: var(--ink); width: 36px; height: 36px; border-radius: 999px; font-size: 25px; line-height: 1; }
.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 8px; }
.settings-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; }
.settings-card .btn-ghost { color: var(--ink); background: #eef2f5; border: 0; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .editor-panel { position: static; max-height: none; }
  .worksheet { width: 100%; }
}
@media (max-width: 720px) {
  .topbar { padding: 12px 14px; align-items: flex-start; }
  .brand-subtitle { display: none; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .btn { padding: 9px 11px; font-size: 12px; }
  .workspace { padding: 12px; gap: 12px; }
  .editor-panel, .worksheet { border-radius: 14px; padding: 18px; }
  .two-col, .four-square-grid, .deal-summary { grid-template-columns: 1fr; }
  .worksheet-header, .worksheet-meta { flex-direction: column; text-align: left; }
  .worksheet-meta { gap: 8px; }
  .customer-strip { grid-template-columns: 1fr; }
  .square-card { min-height: auto; }
  .preset-grid { grid-template-columns: 1fr; }
  .settings-actions { flex-direction: column-reverse; }
}

@media print {
  @page { size: letter portrait; margin: .32in; }
  body { background: #fff; }
  .no-print, dialog { display: none !important; }
  .workspace { display: block; padding: 0; }
  .preview-panel { overflow: visible; }
  .worksheet {
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .worksheet-header { padding-bottom: 10px; }
  .print-brand { font-size: 25px; }
  .customer-strip { padding: 12px 0; }
  .four-square-grid { gap: 10px; }
  .square-card { min-height: 218px; padding: 15px; break-inside: avoid; }
  .square-card h2 { font-size: 30px; margin-bottom: 11px; }
  .down-options { margin-top: 12px; }
  .down-pill { padding: 9px 5px; }
  .payment-table th, .payment-table td { padding: 8px 5px; }
  .deal-summary { margin-top: 10px; }
  .worksheet-footer { margin-top: 12px; }
  .signature-row { margin-top: 20px; }
}
