:root {
  --harbor: #17304f;
  --harbor-2: #22426b;
  --emerald: #1d8a66;
  --gold: #c7932e;
  --ink: #161c26;
  --muted: #5a6372;
  --paper: #f6f7f9;
  --card: #fff;
  --cream: #f1f4f7;
  --line: #e0e5eb;
  --red: #b23a2b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(18, 30, 48, .05), 0 6px 20px rgba(18, 30, 48, .06);
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font: 400 15.5px/1.55 var(--sans); color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; display: flex; flex-direction: column; min-height: 100vh; }
svg { display: block; }
a { color: var(--harbor-2); }
h1, h2, h3 { font-family: var(--serif); color: var(--harbor); line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); }
h2 { font-size: 1.3rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--harbor); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 12px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.container { width: min(1240px, 100% - 32px); margin-inline: auto; }
.container.narrow { width: min(860px, 100% - 32px); }

/* Header */
.app-header { background: var(--harbor); color: #fff; position: sticky; top: 0; z-index: 20; }
.bar { display: flex; align-items: center; gap: 28px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; }
.brand-text { font: 700 1.15rem var(--serif); white-space: nowrap; }
.brand-text span { color: #7fd1b0; }
.brand-text small { font: 500 .8rem var(--sans); color: #b9c7da; margin-left: 4px; letter-spacing: .04em; text-transform: uppercase; }
.app-nav { display: flex; gap: 4px; }
.app-nav a { color: #d6e0ec; text-decoration: none; font-weight: 500; padding: 7px 12px; border-radius: 8px; white-space: nowrap; }
.app-user > * { white-space: nowrap; }
.app-nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.app-nav a[aria-current="page"] { background: rgba(255, 255, 255, .14); color: #fff; }
.app-user { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.app-user a { color: #fff; text-decoration: none; font-weight: 600; }
.app-user form { margin: 0; }
.app-user .link-btn { color: #b9c7da; }

.app-main { flex: 1; padding: 28px 0 56px; }
.app-footer { border-top: 1px solid var(--line); padding: 20px 0; color: var(--muted); font-size: .8rem; }
.app-footer p { margin: 0 0 4px; max-width: 70em; }

/* Building blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.card.flush { padding: 0; overflow: hidden; }
.card.empty { text-align: center; padding: 48px 24px; }
.narrow-card { max-width: 760px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head.sub { margin: 32px 0 12px; align-items: center; }
.page-head p { margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.section-title { margin: 28px 0 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.admin-grid { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: 999px; border: 2px solid var(--harbor);
  background: var(--harbor); color: #fff; font: 600 .95rem var(--sans); text-decoration: none; cursor: pointer;
  transition: background .15s, color .15s;
}
.btn:hover { background: var(--harbor-2); border-color: var(--harbor-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--harbor); }
.btn.ghost:hover { background: var(--harbor); color: #fff; }
.btn.danger { color: var(--red); border-color: rgba(178, 58, 43, .5); }
.btn.danger:hover { background: var(--red); border-color: var(--red); color: #fff; }
.btn.block { width: 100%; }
.small-btn { padding: 5px 14px; font-size: .85rem; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--harbor-2); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; width: 32px; height: 32px; font-size: 1.2rem; line-height: 1; color: var(--muted); cursor: pointer; }
.icon-btn:hover { color: var(--red); border-color: var(--red); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; vertical-align: middle; }
.badge.best { background: var(--emerald); color: #fff; }
.badge.sample { background: rgba(199, 147, 46, .18); color: #7a5410; }
.badge.warn { background: #fbeae7; color: #8a2a1e; }

.flash { padding: 12px 16px; border-radius: 10px; margin: 0 0 18px; border: 1px solid; font-size: .93rem; }
.flash.ok { background: #e9f6f0; border-color: #bfe4d3; color: #145c44; }
.flash.error { background: #fbeae7; border-color: #f0c6bf; color: #7a2418; }
.flash.warn { background: #fdf6e7; border-color: #f0dcae; color: #6b4a0c; }
.flash ul { margin: 6px 0 0; padding-left: 20px; }
.split-flash { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }

/* Forms */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: .86rem; margin-bottom: 5px; }
.field small { font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); }
.field input, .field select, .field textarea, .search input, .sheet input, .sheet select, .reset input {
  width: 100%; padding: 9px 12px; background: #fff; border: 1.5px solid var(--line); border-radius: 8px; font-size: .95rem;
}
.field textarea { resize: vertical; }
.field.inline { display: flex; align-items: center; gap: 12px; max-width: 360px; }
.field.inline label { margin: 0; white-space: nowrap; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .92rem; cursor: pointer; margin: 0 18px 12px 0; }
.check input { width: 17px; height: 17px; accent-color: var(--harbor); }
.checks-row { display: flex; flex-wrap: wrap; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

.filters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 16px; align-items: end; }
.filters .check { grid-column: span 2; margin-bottom: 18px; }
.filters .btn { grid-column: span 2; margin-bottom: 16px; }

.search { display: flex; gap: 10px; max-width: 480px; margin-bottom: 18px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
.data th, .data td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.data thead th { background: var(--cream); font-size: .74rem; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 600; white-space: nowrap; }
.data tbody tr:last-child > * { border-bottom: 0; }
.data .num { text-align: right; }
.data .sel { width: 44px; text-align: center; }
.data .sel input { width: 18px; height: 18px; accent-color: var(--harbor); }
.data tr.inactive td { color: var(--muted); }
.rate { font: 700 1.08rem var(--serif); color: var(--harbor); }
.results tr.best td { background: rgba(29, 138, 102, .06); }
.results tr.best .rate { color: var(--emerald); }
.results tr.picked td { background: rgba(61, 120, 201, .08); }
.results-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 6px 0 12px; }
.results-bar p { margin: 0; }

.side th[scope="row"] { width: 190px; background: var(--cream); font-weight: 600; color: var(--harbor); font-size: .86rem; }
.side thead th { text-transform: none; letter-spacing: 0; font: 700 1.02rem/1.3 var(--serif); color: var(--harbor); white-space: normal; }
.side .col-carrier { font: 600 .74rem var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.side ul.rates { list-style: none; margin: 0; padding: 0; }
.side ul.rates li { padding: 4px 0; }
.side ul.rates li + li { border-top: 1px dashed var(--line); }
.side ul.rates li.top .rate { color: var(--emerald); }
.projection th[scope="row"] { width: 70px; }
.projection tr.total > * { background: var(--cream); font-weight: 700; }
.sheet td { padding: 6px 6px; }
.sheet input.num { text-align: right; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.history li.current a { font-weight: 700; }
.row-actions { white-space: nowrap; }
.row-actions form { display: inline; margin: 0 12px 0 0; }
.reset { display: inline-block; }
.reset summary { list-style: none; display: inline; }
.reset summary::-webkit-details-marker { display: none; }
.reset form { display: flex; gap: 6px; margin-top: 8px; }
.danger-zone { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.danger-zone form { margin: 0; }
.spec { padding-left: 20px; color: var(--muted); }
.spec li { margin-bottom: 4px; }
code { background: var(--cream); padding: 1px 6px; border-radius: 5px; font-size: .88em; color: var(--harbor); }
.save-proposal { margin-top: 24px; }

/* Agencies */
.tree td.name { min-width: 200px; }
.tree td.name.d1 { padding-left: 36px; } .tree td.name.d2 { padding-left: 58px; } .tree td.name.d3 { padding-left: 80px; }
.tree td.name.d4 { padding-left: 102px; } .tree td.name.d5 { padding-left: 124px; }
.tree td.name:not(.d0) { position: relative; }
.tree td.name:not(.d0)::before { content: "↳"; position: absolute; margin-left: -18px; color: var(--muted); }
fieldset.plain { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
fieldset.plain legend { font-weight: 600; font-size: .86rem; margin-bottom: 8px; padding: 0; }

/* Transfers */
.pipeline { display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px; margin-bottom: 18px; }
.stage { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); text-decoration: none; color: var(--muted); font-size: .8rem; line-height: 1.25; }
.stage strong { font: 700 1.5rem var(--serif); color: var(--harbor); }
.stage:hover { border-color: var(--harbor-2); }
.stage.on { border-color: var(--harbor); box-shadow: inset 0 0 0 1px var(--harbor); }
.stage.alert strong { color: var(--red); }
.stage.warn strong { color: #8a6115; }
.stage.total { background: var(--harbor); border-color: var(--harbor); color: #c9d6e8; }
.stage.total strong { color: #fff; }
.filters-inline { display: flex; flex-wrap: wrap; gap: 0 14px; align-items: flex-end; padding: 16px 20px 4px; }
.filters-inline .field { min-width: 160px; }
.filters-inline .grow { flex: 1; min-width: 220px; }
.filters-inline .btn { margin-bottom: 16px; }

.status-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font: 600 .75rem/1.6 var(--sans); white-space: nowrap; vertical-align: middle; background: var(--cream); color: var(--harbor); border: 1px solid var(--line); }
.status-pill.s-submitted, .status-pill.s-requested, .status-pill.s-processing { background: rgba(61, 120, 201, .1); color: #24589e; border-color: rgba(61, 120, 201, .25); }
.status-pill.s-funds_received { background: rgba(29, 138, 102, .1); color: #146b4f; border-color: rgba(29, 138, 102, .3); }
.status-pill.s-issued { background: var(--emerald); color: #fff; border-color: var(--emerald); }
.status-pill.s-on_hold { background: #fdf6e7; color: #7a5410; border-color: #f0dcae; }
.status-pill.s-cancelled { background: #f3f3f3; color: var(--muted); }
h1 .status-pill { font-size: .85rem; }
.data tr.due td { background: #fdf3f1; }
.overdue { color: var(--red); }

.milestones { list-style: none; display: grid; grid-template-columns: repeat(6, 1fr); gap: 0; padding: 0; margin: 0 0 22px; counter-reset: ms; }
.milestones li { position: relative; counter-increment: ms; padding: 40px 8px 0; text-align: center; font-size: .8rem; color: var(--muted); line-height: 1.3; }
.milestones li::before { content: counter(ms); position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: #fff; border: 2px solid var(--line); font-weight: 700; color: var(--muted); z-index: 1; }
.milestones li::after { content: ""; position: absolute; top: 14px; left: -50%; width: 100%; height: 2px; background: var(--line); }
.milestones li:first-child::after { display: none; }
.milestones li.done::before { content: "✓"; background: var(--emerald); border-color: var(--emerald); color: #fff; }
.milestones li.done::after, .milestones li.current::after { background: var(--emerald); }
.milestones li.current::before { border-color: var(--harbor); color: var(--harbor); box-shadow: 0 0 0 4px rgba(23, 48, 79, .12); }
.milestones li.current span { color: var(--harbor); font-weight: 700; }
.milestones.cancelled { opacity: .5; }

.details { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; margin: 0; }
.details div { padding: 9px 0; border-bottom: 1px solid var(--line); }
.details dt { font-size: .72rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.details dd { margin: 2px 0 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--harbor-2); }
.timeline li.k-status::before { background: var(--emerald); border-color: var(--emerald); }
.timeline li.k-followup::before { border-color: var(--gold); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline .when { font-size: .78rem; color: var(--muted); }
.timeline .what p { margin: 4px 0 0; color: var(--ink); }
aside .card h2 { font-size: 1.1rem; }
aside > form:last-child { margin-bottom: 20px; }

/* Sign-in */
.auth-wrap { display: grid; place-items: center; padding: 40px 16px; }
.auth-card { width: min(420px, 100%); padding: 32px; }

/* Proposal */
.proposal { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 36px; }
.proposal-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; border-bottom: 3px solid var(--harbor); padding-bottom: 20px; margin-bottom: 20px; }
.proposal-head h1 { margin-bottom: 4px; }
.eyebrow { font-size: .75rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--emerald); margin: 0 0 6px; }
.prepared-by { font-size: .9rem; color: var(--muted); text-align: right; line-height: 1.5; }
.prepared-by span { display: block; font-size: .72rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
.prepared-by strong { display: block; color: var(--harbor); font: 700 1.1rem var(--serif); }
.facts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 0 0 8px; }
.facts div { background: var(--cream); border-radius: 10px; padding: 10px 14px; }
.facts dt { font-size: .72rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; color: var(--harbor); }
.proposal .card { box-shadow: none; }
.disclosures { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); font-size: .8rem; color: var(--muted); }
.disclosures h2 { font-size: 1rem; }

/* Responsive */
@media (max-width: 1080px) {
  /* Header: nav moves to its own row so it never wraps mid-word. */
  .bar { flex-wrap: wrap; height: auto; padding: 10px 0 6px; gap: 6px 16px; }
  .app-nav { order: 3; width: 100%; overflow-x: auto; margin-left: -12px; scrollbar-width: none; }
  .app-nav::-webkit-scrollbar { display: none; }
}
@media (max-width: 980px) {
  .filters { grid-template-columns: repeat(2, 1fr); }
  .admin-grid { grid-template-columns: 1fr; }
  .facts { grid-template-columns: repeat(3, 1fr); }
  .pipeline { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 720px) {
  .brand-text small { display: none; }
  .grid-2, .filters { grid-template-columns: 1fr; }
  .filters .check, .filters .btn { grid-column: auto; }
  .facts { grid-template-columns: 1fr 1fr; }
  .proposal { padding: 20px; }
  .prepared-by { text-align: left; }
  .side th[scope="row"] { width: 130px; }
  .pipeline { grid-template-columns: repeat(2, 1fr); }
  .milestones { grid-template-columns: 1fr; gap: 8px; }
  .milestones li { padding: 4px 0 4px 42px; text-align: left; min-height: 30px; display: flex; align-items: center; }
  .milestones li::before { left: 15px; top: 50%; transform: translate(-50%, -50%); }
  .milestones li::after { display: none; }
  .details { grid-template-columns: 1fr; }
}

/* Print: proposals print as a clean document */
@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 10.5pt; }
  .app-header, .app-footer, .no-print, .skip, .flash.ok { display: none !important; }
  .app-main { padding: 0; }
  .container { width: 100%; }
  .proposal { border: 0; box-shadow: none; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
  .table-wrap { overflow: visible; }
  .data th, .data td { padding: 6px 8px; }
  .facts div { border: 1px solid var(--line); }
  a { color: inherit; text-decoration: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
