:root {
  color-scheme: light;
  --navy: #172e48;
  --navy-2: #234765;
  --red: #da3e45;
  --red-dark: #bf303a;
  --background: #f4f6f9;
  --surface: #ffffff;
  --soft-blue: #e7edf4;
  --soft-red: #fcecee;
  --text: #172e48;
  --muted: #697386;
  --border: #dce3eb;
  --success: #1f7a58;
  --success-soft: #e6f5ee;
  --warning: #9a6515;
  --warning-soft: #fff5dd;
  --shadow: 0 18px 50px rgba(23, 46, 72, 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--background); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--navy);
  box-shadow: 0 8px 30px rgba(11, 29, 48, 0.2);
}

.header-inner {
  width: min(1180px, calc(100% - 32px));
  min-height: 82px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  color: white;
  text-decoration: none;
}

.brand img {
  width: 174px;
  max-height: 54px;
  object-fit: contain;
}

.brand-divider { width: 1px; height: 38px; background: rgba(255, 255, 255, 0.25); }
.brand-copy { display: grid; gap: 2px; }
.brand-copy strong { font-size: 1rem; letter-spacing: 0.01em; }
.brand-copy small { color: rgba(255, 255, 255, 0.66); font-size: 0.78rem; }

.menu-button {
  display: none;
  width: 48px;
  height: 48px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
}

.menu-button span { display: block; height: 2px; margin: 6px 0; background: white; border-radius: 2px; }

.module-nav {
  position: sticky;
  top: 82px;
  z-index: 20;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(244, 246, 249, 0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.module-link {
  min-height: 46px;
  padding: 12px 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: var(--navy);
  font-weight: 700;
  text-decoration: none;
}

.module-link.is-active { color: white; background: var(--red); box-shadow: 0 8px 24px rgba(218, 62, 69, 0.22); }

#module-root:focus { outline: none; }
.page-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 42px 0 70px; }
.page-loading { min-height: 50vh; display: grid; place-items: center; color: var(--muted); }

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 26px;
}

.eyebrow { color: var(--red); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.11em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(1.85rem, 4vw, 2.65rem); line-height: 1.08; letter-spacing: -0.035em; }
.page-heading p { max-width: 690px; margin-bottom: 0; color: var(--muted); font-size: 1rem; line-height: 1.6; }

.privacy-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--success);
  background: var(--success-soft);
  font-size: 0.82rem;
  font-weight: 700;
}

.privacy-chip span { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; color: white; background: var(--success); }

.upload-card, .results-section {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.drop-zone {
  min-height: 188px;
  margin: 10px;
  padding: 28px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 22px;
  border: 2px dashed #b9c7d5;
  border-radius: 12px;
  transition: 160ms ease;
}

.drop-zone:hover, .drop-zone:focus-visible, .drop-zone.is-dragging { border-color: var(--red); background: var(--soft-red); outline: none; }
.drop-zone h2 { margin-bottom: 7px; font-size: 1.16rem; }
.drop-zone p { margin-bottom: 0; color: var(--muted); line-height: 1.45; }

.upload-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 12px; color: var(--red); background: var(--soft-red); }
.upload-icon svg { width: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.button {
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 9px;
  font-weight: 750;
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.button:hover { transform: translateY(-1px); }
.button:focus-visible { outline: 3px solid rgba(218, 62, 69, 0.24); outline-offset: 2px; }
.button:disabled { cursor: wait; opacity: 0.6; }
.button-primary { color: white; background: var(--red); box-shadow: 0 9px 24px rgba(218, 62, 69, 0.18); }
.button-primary:hover { background: var(--red-dark); }
.button-secondary { color: var(--navy); background: var(--soft-blue); }
.button-ghost { color: var(--muted); background: transparent; }

.processing-row { padding: 0 24px 18px; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--red); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.results-section { margin-top: 28px; padding: 24px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-heading h2 { margin-bottom: 4px; font-size: 1.25rem; }
.section-heading p { margin-bottom: 0; color: var(--muted); font-size: 0.88rem; }
.section-actions { display: flex; gap: 10px; }

.empty-state { min-height: 178px; display: grid; place-content: center; justify-items: center; gap: 8px; border-radius: 12px; color: var(--muted); background: var(--background); text-align: center; }
.empty-state strong { color: var(--navy); }
.result-list { display: grid; gap: 20px; }

.result-card { overflow: hidden; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.result-header { padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--border); }
.file-identity { min-width: 0; display: flex; align-items: center; gap: 12px; }
.file-identity h3 { overflow: hidden; margin-bottom: 3px; font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }
.file-identity p { overflow: hidden; max-width: 630px; margin-bottom: 0; color: var(--muted); font-size: 0.78rem; text-overflow: ellipsis; white-space: nowrap; }
.pdf-mark { flex: 0 0 auto; padding: 6px 7px; border-radius: 6px; color: white; background: var(--red); font-size: 0.68rem; font-weight: 900; letter-spacing: 0.04em; }

.status-badge { flex: 0 0 auto; padding: 8px 11px; border-radius: 999px; font-size: 0.76rem; font-weight: 750; }
.status-badge.is-ready { color: var(--success); background: var(--success-soft); }
.status-badge.is-warning { color: var(--warning); background: var(--warning-soft); }

.result-body { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(340px, 0.75fr); }
.form-panel { padding: 22px; border-right: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 120px minmax(0, 1fr) 120px; gap: 14px; }
.field { min-width: 0; display: grid; gap: 6px; }
.field > span { color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.field.span-2 { grid-column: span 2; }

.field input, .field select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--background);
  font-size: 0.9rem;
}

.field input:focus, .field select:focus { border-color: var(--red); outline: 3px solid rgba(218, 62, 69, 0.11); background: white; }
.field select { appearance: none; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--navy) 50%), linear-gradient(135deg, var(--navy) 50%, transparent 50%); background-position: calc(100% - 17px) 20px, calc(100% - 12px) 20px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

.output-panel { min-width: 0; padding: 22px; display: flex; flex-direction: column; background: #fbfcfe; }
.output-heading { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.output-heading span { color: var(--muted); font-size: 0.75rem; }
.output-text { flex: 1; overflow: auto; min-height: 360px; margin: 0; padding: 16px; border: 1px solid var(--border); border-radius: 9px; color: #24384d; background: white; font: 0.86rem/1.55 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; overflow-wrap: anywhere; }
.output-text p { margin: 0 0 14px; }
.output-text p:last-child { margin-bottom: 0; }
.output-text .output-title { padding-bottom: 12px; border-bottom: 1px solid var(--border); color: var(--navy); font-weight: 750; }
.output-actions { margin-top: 14px; display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; max-width: min(390px, calc(100% - 32px)); padding: 14px 18px; border-radius: 10px; color: white; background: var(--navy); box-shadow: 0 14px 40px rgba(23, 46, 72, 0.28); opacity: 0; transform: translateY(16px); pointer-events: none; transition: 180ms ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast[data-tone="success"] { background: var(--success); }
.toast[data-tone="error"] { background: var(--red-dark); }
.error-panel { padding: 28px; border: 1px solid #f3c9cc; border-radius: 14px; color: var(--red-dark); background: var(--soft-red); }

.proposal-workspace {
  display: grid;
  grid-template-columns: minmax(420px, 0.82fr) minmax(510px, 1.18fr);
  gap: 24px;
  align-items: start;
}

.proposal-form-card,
.proposal-preview-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.proposal-form-card { padding: 24px; }
.proposal-preview-card { position: sticky; top: 154px; padding: 18px; background: #e7ebf0; }
.proposal-form-card h2,
.proposal-preview-toolbar h2 { margin-bottom: 5px; font-size: 1.08rem; }
.proposal-form-card > p,
.proposal-preview-toolbar p { margin-bottom: 0; color: var(--muted); font-size: 0.84rem; line-height: 1.5; }

.proposal-form {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}

.proposal-form .field-wide { grid-column: 1 / -1; }
.proposal-form .field input { min-height: 48px; background: #fbfcfe; }
.proposal-form .field input[readonly] { color: var(--navy); background: var(--soft-blue); font-weight: 750; }
.proposal-form .field small { color: var(--muted); font-size: 0.72rem; line-height: 1.4; }

.filename-panel {
  grid-column: 1 / -1;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--background);
}

.filename-panel span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.filename-panel strong { display: block; overflow-wrap: anywhere; color: var(--navy); font-size: 0.84rem; line-height: 1.5; }
.filename-panel small { display: block; margin-top: 7px; color: var(--success); font-size: 0.75rem; font-weight: 700; line-height: 1.45; }
.proposal-download { grid-column: 1 / -1; width: 100%; margin-top: 2px; }

.proposal-preview-toolbar { margin-bottom: 14px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.proposal-preview-scale { color: var(--muted); font-size: 0.72rem; font-weight: 750; }
.proposal-page-wrap { overflow: auto; padding: 8px; border-radius: 10px; background: #dfe4ea; }

.proposal-page {
  position: relative;
  isolation: isolate;
  container-type: inline-size;
  width: 100%;
  aspect-ratio: 210 / 297;
  overflow: hidden;
  padding: 16% 7.8% 6.5%;
  color: #171717;
  background: #fff;
  box-shadow: 0 8px 28px rgba(23, 46, 72, 0.16);
  font-family: Calibri, "Segoe UI", sans-serif;
}

.proposal-page::before {
  content: "";
  position: absolute;
  z-index: 1;
  top: 1.9%;
  left: 1%;
  width: 95.2%;
  aspect-ratio: 1241 / 152;
  background: url("./proposta-header.jpg") center / contain no-repeat;
}

.proposal-page::after {
  content: "";
  position: absolute;
  z-index: 0;
  left: 3.6%;
  bottom: 0.5%;
  width: 93.8%;
  aspect-ratio: 1242 / 1169;
  background: url("./proposta-watermark.jpg") center / contain no-repeat;
}

.proposal-page > * { position: relative; z-index: 2; }
.proposal-doc-date { margin: 0 0 4.5%; text-align: right; font-size: 11pt; font-weight: 400 !important; }
.proposal-doc-number { margin: 0 0 4.4%; text-align: center; font-size: clamp(8px, 1.45vw, 14px); font-weight: 700; }
.proposal-doc-address { margin-bottom: 3.6%; font-size: clamp(7px, 1.28vw, 12px); line-height: 1.5; }
.proposal-doc-address strong { display: block; }
.proposal-doc-intro { margin-bottom: 3.6%; font-size: clamp(7px, 1.2vw, 11.5px); line-height: 1.5; }
.proposal-doc-intro span { display: block; padding-left: 7%; }
.proposal-section-title { margin-bottom: 3.2%; color: #172e48; font-size: clamp(7px, 1.3vw, 12.5px); }
.proposal-section-title strong { font-weight: 750; }

.proposal-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: clamp(5.5px, 0.93vw, 9.5px);
}

.proposal-table th,
.proposal-table td { height: 29px; padding: 3px 4px; border: 1px solid #111; text-align: center; vertical-align: middle; overflow-wrap: anywhere; }
.proposal-table th { height: 26px; background: #8bd8ef; font-weight: 700; }
.proposal-table th:nth-child(1), .proposal-table td:nth-child(1) { width: 16.1%; }
.proposal-table th:nth-child(2), .proposal-table td:nth-child(2) { width: 17.4%; }
.proposal-table th:nth-child(3), .proposal-table td:nth-child(3) { width: 13.4%; }
.proposal-table th:nth-child(4), .proposal-table td:nth-child(4) { width: 8%; }
.proposal-table th:nth-child(5), .proposal-table td:nth-child(5) { width: 6.7%; }
.proposal-table th:nth-child(6), .proposal-table td:nth-child(6) { width: 12%; }
.proposal-table th:nth-child(7), .proposal-table td:nth-child(7) { width: 12%; }
.proposal-table th:nth-child(8), .proposal-table td:nth-child(8) { width: 12%; }

.proposal-fixed-copy { margin-top: 3%; font-size: clamp(5.7px, 0.93vw, 9.5px); line-height: 1.45; }
.proposal-fixed-copy h4 { margin: 0 0 0.5%; color: #172e48; font-size: 1.1em; }
.proposal-fixed-copy p { margin: 0 0 1.6%; }
.proposal-fixed-copy .proposal-insurance-copy { padding-left: 4%; text-align: justify; }
.proposal-fixed-copy .closing { margin-top: 5%; font-style: italic; }

@media (max-width: 1080px) {
  .proposal-workspace { grid-template-columns: 1fr; }
  .proposal-preview-card { position: static; }
  .proposal-page { max-width: 760px; margin: 0 auto; }
}

@media (max-width: 980px) {
  .result-body { grid-template-columns: 1fr; }
  .form-panel { border-right: 0; border-bottom: 1px solid var(--border); }
  .result-body .output-text { min-height: 290px; }
}

@media (max-width: 720px) {
  .header-inner { width: min(100% - 24px, 1180px); min-height: 72px; }
  .brand { gap: 10px; }
  .brand img { width: 132px; }
  .brand-divider, .brand-copy { display: none; }
  .menu-button { display: block; }
  .module-nav { top: 72px; display: none; padding: 10px 12px; }
  .module-nav.is-open { display: flex; }
  .module-link { width: 100%; }
  .page-shell { width: min(100% - 24px, 1180px); padding: 28px 0 50px; }
  .page-heading { display: block; }
  .privacy-chip { margin-top: 18px; }
  .drop-zone { grid-template-columns: 1fr; justify-items: center; padding: 26px 18px; text-align: center; }
  .drop-zone .button { width: 100%; }
  .results-section { padding: 14px; }
  .section-heading { align-items: flex-start; }
  .section-actions { flex-direction: column-reverse; }
  .section-actions .button { min-height: 42px; }
  .result-header { align-items: flex-start; flex-direction: column; }
  .status-badge { align-self: flex-start; }
  .form-panel, .output-panel { padding: 16px; }
  .form-grid { grid-template-columns: minmax(0, 1fr) 88px; }
  .field.span-2 { grid-column: 1 / -1; }
  .output-heading { flex-direction: column; }
  .output-actions { flex-direction: column-reverse; }
  .output-actions .button { width: 100%; }
  .toast { right: 16px; bottom: 16px; }
  .proposal-form-card, .proposal-preview-card { padding: 15px; }
  .proposal-form { grid-template-columns: 1fr; }
  .proposal-form .field-wide, .proposal-download, .filename-panel { grid-column: 1; }
  .proposal-preview-toolbar { display: block; }
  .proposal-preview-scale { display: inline-block; margin-top: 8px; }
  .proposal-page-wrap { padding: 0; }
}

@media (max-width: 430px) {
  .page-heading h1 { font-size: 1.75rem; }
  .form-grid { grid-template-columns: 1fr 74px; gap: 12px 8px; }
  .field:not(.field-short) { grid-column: 1 / -1; }
  .field.field-short { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
