:root {
  --navy: #0f3557;
  --navy-2: #174e78;
  --blue: #23689b;
  --sky: #eaf3f9;
  --ink: #17212b;
  --muted: #64717d;
  --line: #dbe3e8;
  --panel: #ffffff;
  --bg: #f3f6f8;
  --input: #fff8d8;
  --good: #137a51;
  --warn: #9a6500;
  --bad: #b42318;
  --shadow: 0 14px 45px rgba(15, 53, 87, .09);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100%; color: var(--ink); background: linear-gradient(180deg, #eef4f7 0, var(--bg) 280px); font-family: Arial, Helvetica, sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar { height: 76px; padding: 0 32px; display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--navy); color: #fff; font-weight: 800; letter-spacing: .05em; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.privacy-badge { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; color: var(--good); padding: 8px 11px; background: #ebf8f2; border: 1px solid #c8e9db; border-radius: 999px; }
.privacy-badge span { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 4px rgba(19,122,81,.1); }
.privacy-actions { display: flex; align-items: center; gap: 10px; }

.app-shell { max-width: 1380px; margin: 0 auto; padding: 28px 30px 50px; display: grid; grid-template-columns: 230px 1fr; gap: 24px; }
.step-nav { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 104px; align-self: start; }
.step { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; border: 0; border-radius: 12px; background: transparent; color: var(--muted); padding: 11px; }
.step b { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid #cdd8df; background: #fff; border-radius: 50%; font-size: 12px; }
.step span { font-size: 13px; font-weight: 700; }
.step:hover { background: rgba(255,255,255,.7); }
.step.active { background: #fff; color: var(--navy); box-shadow: 0 6px 24px rgba(15,53,87,.07); }
.step.active b { border-color: var(--navy); background: var(--navy); color: #fff; }
.step.complete b { border-color: var(--good); color: #fff; background: var(--good); }

.workspace { min-width: 0; }
.panel { background: var(--panel); border: 1px solid rgba(215,225,231,.9); box-shadow: var(--shadow); border-radius: 18px; padding: 28px; }
.step-panel { display: none; }
.step-panel.active { display: block; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); padding-bottom: 21px; margin-bottom: 24px; }
.panel-heading h2 { margin: 3px 0 7px; font-size: 25px; letter-spacing: -.025em; color: var(--navy); }
.panel-heading p:not(.eyebrow) { margin: 0; max-width: 720px; color: var(--muted); line-height: 1.55; font-size: 13px; }
.eyebrow { margin: 0; text-transform: uppercase; font-size: 10px; font-weight: 800; letter-spacing: .12em; color: var(--blue); }

.button { border-radius: 9px; padding: 10px 15px; border: 1px solid transparent; font-weight: 750; font-size: 12px; transition: .18s ease; white-space: nowrap; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: #fff; background: var(--navy); border-color: var(--navy); box-shadow: 0 6px 15px rgba(15,53,87,.18); }
.button.secondary { color: var(--navy); background: #edf4f8; border-color: #cbdde8; }
.button.ghost { color: var(--navy); background: #fff; border-color: var(--line); }
.button.small { padding: 7px 11px; }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.text-button { border: 0; background: transparent; padding: 3px; color: var(--blue); font-size: 12px; font-weight: 700; }

.upload-zone { min-height: 205px; border: 1.5px dashed #9db7c9; border-radius: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: linear-gradient(180deg,#f9fcfe,#f3f8fb); transition: .2s ease; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--blue); background: var(--sky); }
.upload-zone input { position: absolute; opacity: 0; pointer-events: none; }
.upload-zone strong { color: var(--navy); font-size: 15px; }
.upload-zone small { color: var(--muted); }
.upload-icon { width: 46px; height: 46px; display: grid; place-items: center; background: #fff; border: 1px solid #cfdee7; color: var(--blue); border-radius: 13px; font-size: 25px; font-weight: 400; box-shadow: 0 6px 20px rgba(15,53,87,.08); }

.status-card { margin-top: 17px; border: 1px solid #cbdde8; background: #f4f9fc; border-radius: 12px; padding: 15px; }
.status-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--navy); }
.status-card p { margin: 9px 0 0; color: var(--muted); font-size: 12px; }
.progress { height: 6px; margin-top: 10px; background: #dce9f0; border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--blue); transition: width .3s ease; }

.review-grid { margin-top: 22px; display: grid; grid-template-columns: .85fr 1.15fr; gap: 16px; }
.summary-card { border: 1px solid var(--line); border-radius: 13px; padding: 17px; min-height: 178px; }
.summary-card h3 { margin: 0 0 14px; font-size: 14px; color: var(--navy); }
.summary-card dl { margin: 0; display: grid; gap: 10px; }
.summary-card dl div { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 8px; border-bottom: 1px solid #eef2f4; }
.summary-card dt { color: var(--muted); font-size: 12px; }
.summary-card dd { margin: 0; font-size: 12px; font-weight: 700; text-align: right; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.raw-text { width: 100%; height: 260px; resize: vertical; border: 1px solid var(--line); border-radius: 9px; padding: 11px; color: #34414d; font: 11px/1.55 Consolas, monospace; }
.muted { color: var(--muted); font-size: 12px; line-height: 1.55; }

.form-section { border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 17px; }
.form-section h3 { margin: 0 0 15px; color: var(--navy); font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 15px; }
.form-grid label { min-width: 0; }
.form-grid label.wide { grid-column: span 2; }
.form-grid label.full { grid-column: 1 / -1; }
label > span { display: block; margin: 0 0 6px; color: #46535e; font-size: 11px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cfd9df; color: var(--ink); border-radius: 8px; padding: 10px 11px; background: var(--input); outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(35,104,155,.12); }
textarea.field-textarea { min-height: 92px; resize: vertical; line-height: 1.45; }
.calculation-strip { display: grid; grid-template-columns: repeat(3,1fr); gap: 1px; background: #d8e4eb; border: 1px solid #d8e4eb; border-radius: 11px; overflow: hidden; margin-top: 17px; }
.calculation-strip div { background: #f6fafc; padding: 14px; }
.calculation-strip span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 5px; }
.calculation-strip strong { font-size: 14px; color: var(--navy); }

.conditions-editor { min-height: 450px; resize: vertical; font: 12px/1.65 Arial, sans-serif; padding: 16px; background: #fffdf1; }
.condition-toolbar { display: flex; justify-content: space-between; margin-bottom: 9px; color: var(--muted); font-size: 11px; }
.warning-text { color: var(--warn); }
.phase-list { display: grid; gap: 10px; }
.phase-row { display: grid; grid-template-columns: 140px 150px 1fr 34px; gap: 8px; align-items: start; }
.phase-row textarea { min-height: 64px; resize: vertical; }
.remove-phase { width: 34px; height: 34px; padding: 0; border: 1px solid #ecc7c3; color: var(--bad); background: #fff5f4; border-radius: 8px; }
.phase-total { margin-top: 12px; display: flex; justify-content: flex-end; align-items: center; gap: 12px; font-size: 12px; }
.phase-total strong { color: var(--navy); }
.phase-total em { font-style: normal; font-weight: 700; }
.phase-total em.good { color: var(--good); }
.phase-total em.bad { color: var(--bad); }

.panel-actions { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 19px; display: flex; justify-content: space-between; }
.save-state { color: var(--good); font-size: 11px; font-weight: 700; }
.validation-box { margin-bottom: 16px; border-radius: 12px; padding: 13px 15px; font-size: 12px; line-height: 1.5; }
.validation-box.good { color: #0c6844; background: #eaf8f2; border: 1px solid #c6e8d9; }
.validation-box.bad { color: #8d2018; background: #fff1ef; border: 1px solid #f0c5c1; }
.validation-box ul { margin: 7px 0 0 18px; padding: 0; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 14px; background: #eef4f8; border: 1px solid #d3e0e8; border-radius: 12px; margin-bottom: 16px; }
.preview-toolbar strong { display: block; font-size: 12px; color: var(--navy); }
.preview-toolbar span { display: block; margin-top: 3px; font-size: 10px; color: var(--muted); }
.toolbar-actions { display: flex; gap: 8px; }

.letter-preview { background: #e6ebee; padding: 24px; border-radius: 14px; max-height: 760px; overflow: auto; }
.letter-page { width: min(100%, 794px); min-height: 1123px; margin: 0 auto 20px; padding: 55px 58px 48px; background: #fff; color: #111; box-shadow: 0 8px 26px rgba(26,39,49,.13); font: 10.5px/1.32 Calibri, Arial, sans-serif; }
.letter-page p { margin: 0 0 7px; }
.letter-ref { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 13px; }
.letter-borrowers { font-weight: 700; margin-bottom: 12px; }
.letter-subject { margin: 14px 0 !important; }
.letter-section { display: inline-block; margin: 6px 0 5px; padding: 2px 4px; background: #d9d9d9; font-weight: 800; font-size: 11px; }
.debt-table { width: 100%; border-collapse: collapse; margin-bottom: 7px; }
.debt-table td { padding: 2px 4px; vertical-align: top; }
.debt-table td:first-child { width: 28%; font-weight: 700; }
.debt-table td:nth-child(2) { width: 2%; }
.phase-plan-table { width: 100%; border-collapse: collapse; margin: 3px 0 8px; }
.phase-plan-table th, .phase-plan-table td { border: 1px solid #777; padding: 3px 4px; vertical-align: top; text-align: left; }
.phase-plan-table th { background: #ededed; font-weight: 800; }
.phase-plan-table th:first-child, .phase-plan-table td:first-child { width: 13%; }
.phase-plan-table th:nth-child(2), .phase-plan-table td:nth-child(2) { width: 17%; }
.condition-heading { font-weight: 800; text-decoration: underline; margin-top: 6px !important; }
.letter-list { margin: 0 0 6px; padding: 0 0 0 18px; }
.letter-list li { margin: 0 0 2px; }
.address-heading { text-align: center; font-weight: 800; text-decoration: underline; margin-top: 6px !important; }
.address-text { text-align: center; }
.doc-list { margin: 0 0 8px 22px; padding-left: 8px; }
.signature-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.signature-table td { border: 1px solid #222; padding: 4px 6px; width: 50%; }
.acceptance { border: 1px solid #222; border-top: 0; padding: 7px; }
.signature-lines { display: grid; grid-template-columns: 1fr 1fr; gap: 75px; margin-top: 30px; }
.signature-lines span { border-top: 1px solid #222; padding-top: 3px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%,20px); background: #17212b; color: #fff; border-radius: 9px; padding: 11px 15px; font-size: 12px; opacity: 0; pointer-events: none; transition: .2s ease; z-index: 80; }
.toast.show { opacity: 1; transform: translate(-50%,0); }

@media (max-width: 900px) {
  .topbar { padding: 0 16px; }
  .privacy-badge { display: none; }
  .privacy-actions { gap: 0; }
  .app-shell { display: block; padding: 18px 12px 35px; }
  .step-nav { position: static; flex-direction: row; overflow-x: auto; margin-bottom: 12px; }
  .step { min-width: 155px; }
  .panel { padding: 19px; border-radius: 14px; }
  .panel-heading, .preview-toolbar { align-items: stretch; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid label.wide, .form-grid label.full { grid-column: auto; }
  .review-grid { grid-template-columns: 1fr; }
  .calculation-strip { grid-template-columns: 1fr; }
  .phase-row { grid-template-columns: 1fr; }
  .toolbar-actions { flex-wrap: wrap; }
  .letter-preview { padding: 8px; }
  .letter-page { padding: 34px 30px; min-height: auto; }
}

@media print {
  body { background: #fff; }
  .topbar, .step-nav, .panel-heading, .validation-box, .preview-toolbar, .panel-actions { display: none !important; }
  .app-shell, .workspace, .panel { display: block; margin: 0; padding: 0; max-width: none; border: 0; box-shadow: none; }
  .step-panel { display: none !important; }
  .step-panel[data-panel="4"] { display: block !important; }
  .letter-preview { background: #fff; padding: 0; max-height: none; overflow: visible; }
  .letter-page { width: auto; min-height: auto; padding: 0; margin: 0; box-shadow: none; font-size: 9.5pt; }
  @page { size: A4; margin: 15mm 16mm 14mm; }
}
