:root {
  --ink: #17221d;
  --muted: #68716c;
  --paper: #f7f5ef;
  --surface: #fffefa;
  --line: #dcded8;
  --green: #176c50;
  --green-dark: #0d513b;
  --green-soft: #dcebe3;
  --orange: #bd5b31;
  --orange-soft: #f5e5dc;
  --blue-soft: #e3ebef;
  --danger: #9f2f2f;
  --shadow: 0 24px 70px rgba(31, 51, 41, .10);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: Inter, Aptos, "Segoe UI", system-ui, sans-serif; line-height: 1.5; }
button, input, textarea, select { font: inherit; }
button { touch-action: manipulation; }
.is-hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; padding: .7rem 1rem; color: white; background: var(--ink); border-radius: 8px; }
.skip-link:focus { top: 1rem; }
:focus-visible { outline: 3px solid #e9954a; outline-offset: 3px; }

.topbar { min-height: 76px; padding: 14px clamp(18px, 4vw, 64px); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(23,34,29,.12); }
.brand { display: inline-flex; align-items: center; gap: .65rem; color: var(--ink); text-decoration: none; font-size: 1.25rem; font-weight: 700; letter-spacing: -.04em; }
.brand-mark { width: 33px; height: 33px; display: grid; place-items: center; border-radius: 10px 10px 10px 3px; background: var(--green); color: white; font-family: Georgia, serif; font-style: italic; font-size: 1.35rem; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.provider-pill { min-height: 40px; display: inline-flex; align-items: center; gap: .45rem; padding: .45rem .75rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; font-size: .74rem; cursor: pointer; }
.provider-pill.is-connected { border-color: #b8d9c9; background: var(--green-soft); color: var(--green-dark); }
.provider-light { width: 8px; height: 8px; border-radius: 50%; background: #9da49f; }
.provider-pill.is-connected .provider-light { background: #1a8a62; box-shadow: 0 0 0 3px rgba(26,138,98,.13); }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer; }

.hero { min-height: calc(100dvh - 76px); max-width: 1240px; margin: 0 auto; padding: clamp(54px, 10vw, 120px) clamp(20px, 6vw, 80px); display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr); gap: clamp(48px, 8vw, 110px); align-items: center; }
.eyebrow { margin: 0 0 .7rem; color: var(--green); font-size: .72rem; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.hero h1 { margin: 0; max-width: 720px; font-size: clamp(3rem, 7.2vw, 6.8rem); line-height: .9; letter-spacing: -.065em; font-weight: 600; }
.hero-copy { min-width: 0; }
.hero h1 em { color: var(--green); font-family: Georgia, serif; font-weight: 500; }
.hero-lede { max-width: 630px; margin: 2rem 0; color: #46504b; font-size: clamp(1.05rem, 2vw, 1.3rem); }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.microcopy { color: var(--muted); font-size: .8rem; margin-top: 1.2rem; }
.button { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: .75rem; padding: .72rem 1.15rem; border: 1px solid transparent; border-radius: 11px; font-weight: 650; cursor: pointer; transition: transform .16s ease, background .16s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--green); color: white; box-shadow: 0 9px 24px rgba(23,108,80,.2); }
.button-primary:hover { background: var(--green-dark); }
.button-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.button-quiet { background: transparent; color: var(--ink); border-color: #b9bdb8; }
.button-danger { background: var(--danger); color: white; }

.hero-card { background: var(--ink); color: white; border-radius: 26px; padding: 1.5rem; box-shadow: var(--shadow); transform: rotate(1.5deg); }
.hero-card-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 1.1rem; border-bottom: 1px solid rgba(255,255,255,.16); font-size: .85rem; }
.status-dot { padding: .25rem .6rem; border-radius: 999px; background: rgba(255,255,255,.12); color: #c6e9d9; font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; }
.process-list { list-style: none; padding: 0; margin: .35rem 0 0; }
.process-list li { display: grid; grid-template-columns: 42px 1fr; gap: 10px; padding: 1.2rem 0; border-bottom: 1px solid rgba(255,255,255,.12); }
.step-number { color: #87bea9; font-family: Georgia, serif; font-style: italic; }
.process-list strong { font-weight: 600; }
.process-list p { margin: .25rem 0 0; color: #b9c2bd; font-size: .85rem; }
.trust-note { margin-top: 1.2rem; padding: .85rem; border-radius: 10px; background: rgba(101,196,157,.11); color: #cde9dc; font-size: .78rem; }
.trust-note span { margin-right: .5rem; }

.app-shell { min-height: calc(100dvh - 76px); display: grid; grid-template-columns: 260px 1fr; }
.sidebar { position: sticky; top: 0; height: calc(100dvh - 76px); padding: 2rem 1.1rem 1.2rem; display: flex; flex-direction: column; justify-content: space-between; border-right: 1px solid var(--line); background: #f0eee7; }
.sidebar-label { margin: 0 0 1rem; padding: 0 .7rem; color: var(--muted); font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
.nav-step { width: 100%; min-height: 56px; display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: center; padding: .6rem .7rem; border: 0; border-radius: 10px; background: transparent; color: var(--muted); text-align: left; cursor: pointer; }
.nav-step > span { grid-row: 1 / 3; width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid #c7cac5; border-radius: 50%; font-size: .72rem; }
.nav-step small { font-size: .67rem; }
.nav-step.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 4px 18px rgba(31,51,41,.06); }
.nav-step.is-active > span { border-color: var(--green); background: var(--green); color: white; }
.sidebar-footer { display: flex; flex-direction: column; gap: .3rem; }
.text-button { min-height: 44px; padding: .55rem .7rem; border: 0; background: transparent; color: var(--muted); text-align: left; cursor: pointer; }
.danger-text { color: var(--danger); }

.workspace { min-width: 0; padding: 0 clamp(20px, 5vw, 72px) 5rem; }
.demo-banner { max-width: 1040px; margin: 1rem auto; padding: .7rem 1rem; display: flex; gap: .7rem; align-items: center; border-radius: 10px; background: var(--blue-soft); color: #3c5966; font-size: .78rem; }
.demo-banner strong { flex: 0 0 auto; color: #274654; }
.workflow-message { max-width: 1040px; margin: 0 auto; padding: .8rem 1rem; border-left: 4px solid var(--green); background: var(--green-soft); color: var(--green-dark); border-radius: 8px; font-size: .85rem; }
.action-error { margin: .75rem 0; padding: .8rem 1rem; border-left: 4px solid var(--danger); border-radius: 8px; background: #fbeceb; color: #812121; font-size: .85rem; overflow-wrap: anywhere; }
.view { max-width: 1040px; margin: 0 auto; padding-top: clamp(2rem, 6vw, 5.5rem); }
.view-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5rem; margin-bottom: 2rem; }
.view-heading h2 { margin: 0; font-size: clamp(2.1rem, 4vw, 3.7rem); line-height: 1; letter-spacing: -.05em; }
.view-heading p:not(.eyebrow) { margin: .8rem 0 0; color: var(--muted); }
.save-state { flex: 0 0 auto; padding: .45rem .65rem; border-radius: 999px; color: var(--green); background: var(--green-soft); font-size: .72rem; }

.form-section { margin-bottom: 1rem; padding: clamp(1.25rem, 3vw, 2rem); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.section-heading { display: flex; gap: 1rem; align-items: flex-start; margin-bottom: 1.6rem; }
.section-heading h3, .section-heading p { margin: 0; }
.section-heading p { color: var(--muted); font-size: .83rem; }
.section-icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px; background: var(--green-soft); color: var(--green); font-family: Georgia, serif; font-style: italic; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1rem; }
label { display: flex; flex-direction: column; gap: .45rem; margin-bottom: 1rem; color: #35413b; font-size: .8rem; font-weight: 650; }
input, textarea, select { width: 100%; border: 1px solid #cfd3cd; border-radius: 9px; background: #fff; color: var(--ink); padding: .8rem .9rem; font-size: .93rem; font-weight: 400; }
textarea { resize: vertical; min-height: 90px; }
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23,108,80,.1); outline: 0; }
[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .72rem; font-weight: 500; }
.form-actions { margin-top: 1.5rem; display: flex; justify-content: flex-end; align-items: center; gap: 1rem; }
.form-hint { margin-right: auto; max-width: 420px; color: var(--muted); font-size: .75rem; }
.untrusted-note { display: flex; gap: .75rem; padding: .9rem; border-radius: 10px; background: var(--orange-soft); color: #70422e; font-size: .8rem; }
.untrusted-note > span { flex: 0 0 auto; width: 22px; height: 22px; display: grid; place-items: center; border: 1px solid #dca183; border-radius: 50%; font-weight: 700; }
.untrusted-note p { margin: 0; }
.document-upload { display: grid; grid-template-columns: 1fr minmax(180px, .8fr) auto; gap: 1rem; align-items: end; margin: 0 0 1.4rem; padding: 1rem; border: 1px dashed #b8c1bb; border-radius: 12px; background: #f8faf7; }
.document-upload label { margin: 0; }
.document-upload p { margin: .25rem 0 0; color: var(--muted); font-size: .74rem; }
.document-upload input { min-height: 48px; padding: .55rem; background: white; }
.processing-status { margin: .75rem 0; padding: .8rem 1rem; display: flex; align-items: center; gap: .7rem; border-radius: 10px; background: var(--green-soft); color: var(--green-dark); font-size: .82rem; }
.processing-status.dark { background: #243b31; color: #d8ece2; }
.spinner { width: 18px; height: 18px; flex: 0 0 auto; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.score-orbit { flex: 0 0 auto; width: 106px; height: 106px; display: grid; place-content: center; border: 9px solid var(--green-soft); border-top-color: var(--green); border-radius: 50%; text-align: center; transform: rotate(4deg); }
.score-orbit strong { font-size: 2.2rem; line-height: .9; }
.score-orbit span { color: var(--muted); font-size: .72rem; }
.gate-panel { display: grid; gap: .6rem; margin-bottom: 1rem; }
.gate { display: flex; gap: .8rem; align-items: flex-start; padding: .85rem 1rem; border-radius: 11px; background: var(--surface); border: 1px solid var(--line); font-size: .83rem; }
.gate strong { margin-right: .3rem; }
.gate .gate-status { flex: 0 0 auto; min-width: 60px; padding: .22rem .45rem; border-radius: 999px; text-align: center; font-size: .65rem; font-weight: 700; }
.gate.pass .gate-status { background: var(--green-soft); color: var(--green-dark); }
.gate.flag .gate-status { background: var(--orange-soft); color: #814524; }
.score-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin: 1.2rem 0; }
.score-card { padding: 1.1rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.score-card p { margin: 0; color: var(--muted); font-size: .74rem; }
.score-card strong { display: block; margin: .4rem 0; font-size: 1.8rem; }
.score-bar { height: 5px; overflow: hidden; border-radius: 99px; background: #e6e8e3; }
.score-bar span { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.insight-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.insight-card { padding: 1.5rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.insight-card h3 { margin: .5rem 0 .9rem; }
.insight-card li { margin-bottom: .6rem; color: #46504b; }
.card-kicker { display: inline-block; padding: .27rem .52rem; border-radius: 999px; font-size: .67rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.positive { background: var(--green-soft); color: var(--green-dark); }
.caution { background: var(--orange-soft); color: #814524; }
.recommendation { margin-top: 1rem; padding: 1.6rem; display: flex; gap: 1.2rem; justify-content: space-between; align-items: center; border-radius: var(--radius); background: var(--ink); color: white; }
.recommendation h3, .recommendation p { margin: 0; }
.recommendation p:not(.eyebrow) { margin-top: .35rem; color: #c7cfcb; }

.document-actions { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: flex-end; }
.document-tabs { display: flex; gap: .2rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.document-tabs button { min-height: 46px; padding: .6rem 1rem; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.document-tabs button[aria-selected="true"] { border-color: var(--green); color: var(--ink); font-weight: 700; }
.document-shell { overflow: auto; padding: clamp(.5rem, 3vw, 2.5rem); background: #e5e3dc; border-radius: 16px; }
.document-page { width: min(100%, 760px); min-height: 980px; margin: 0 auto; padding: clamp(2rem, 6vw, 4.5rem); background: white; color: #1b201d; box-shadow: 0 10px 40px rgba(25,34,29,.13); font-family: Arial, sans-serif; outline: 0; }
.document-page:focus { box-shadow: 0 0 0 3px #e9954a, 0 10px 40px rgba(25,34,29,.13); }
.document-page h1 { margin: 0; font-size: 2rem; letter-spacing: -.04em; }
.document-page h2 { margin: 1.5rem 0 .6rem; padding-bottom: .28rem; border-bottom: 1px solid #9da59f; color: var(--green-dark); font-size: .9rem; text-transform: uppercase; letter-spacing: .09em; }
.document-page h3 { margin: .9rem 0 .15rem; font-size: .95rem; }
.document-page p, .document-page li { font-size: .79rem; line-height: 1.5; }
.document-page ul { padding-left: 1.2rem; }
.document-page sup { display: inline-grid; place-items: center; width: 17px; height: 17px; margin-left: .25rem; border-radius: 50%; background: var(--green-soft); color: var(--green-dark); font-size: .58rem; font-weight: 700; cursor: help; }
.document-page.letter p { font-size: .88rem; line-height: 1.65; }
.document-contact { color: #58605c; }
.edit-note { color: var(--muted); font-size: .75rem; }
.source-note { color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }

.tracker-list { display: grid; gap: .8rem; }
.tracker-empty { padding: 3rem 1.5rem; border: 1px dashed #bdc2bc; border-radius: var(--radius); text-align: center; color: var(--muted); }
.tracker-card { padding: 1.2rem 1.4rem; display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: center; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.tracker-card h3, .tracker-card p { margin: 0; }
.tracker-card p { color: var(--muted); font-size: .78rem; }
.tracker-card select { min-width: 145px; margin: 0; }

dialog { width: min(92vw, 520px); padding: 2rem; border: 0; border-radius: 20px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }
dialog[open] { max-height: min(90dvh, 760px); overflow-y: auto; }
dialog code { font-size: .9em; overflow-wrap: anywhere; }
dialog ol { padding-left: 1.3rem; }
dialog li { margin-bottom: .45rem; }
dialog::backdrop { background: rgba(20,29,25,.55); backdrop-filter: blur(4px); }
.dialog-close { float: right; width: 40px; height: 40px; border: 0; background: transparent; font-size: 1.7rem; cursor: pointer; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.5rem; }
.provider-warning { margin: .2rem 0 1rem; padding: .9rem; border-radius: 10px; background: var(--orange-soft); color: #70422e; font-size: .79rem; }
.provider-warning p { margin: .25rem 0 .45rem; }
.provider-warning a { color: #71381f; font-weight: 700; }
.check-label { display: grid; grid-template-columns: 22px 1fr; gap: .65rem; align-items: start; font-weight: 500; }
.check-label input { width: 20px; height: 20px; margin: 0; }
.full-width { width: 100%; }
.toast { position: fixed; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 50; max-width: 340px; padding: .8rem 1rem; border-radius: 10px; background: var(--ink); color: white; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; padding-top: 52px; }
  .hero-card { transform: none; }
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: .5rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar > div:first-child { overflow-x: auto; }
  .sidebar-label { display: none; }
  .sidebar nav { display: flex; }
  .nav-step { width: auto; min-width: 128px; grid-template-columns: 28px 1fr; }
  .sidebar-footer { flex-direction: row; justify-content: flex-end; border-top: 1px solid var(--line); }
  .sidebar-footer .text-button { min-height: 44px; }
  .workspace { padding-inline: 16px; }
  .score-grid { grid-template-columns: repeat(2, 1fr); }
  .view-heading { flex-wrap: wrap; }
}

@media (max-width: 560px) {
  .topbar { min-height: 64px; padding: 10px 16px; }
  .privacy-pill { display: none; }
  .hero { min-height: calc(100dvh - 64px); padding-inline: 18px; }
  .hero h1 { font-size: clamp(2.8rem, 13.5vw, 4rem); }
  .hero-actions .button { width: 100%; }
  .form-grid, .insight-grid, .score-grid { grid-template-columns: 1fr; }
  .document-upload { grid-template-columns: 1fr; align-items: stretch; }
  .form-actions, .recommendation { align-items: stretch; flex-direction: column-reverse; }
  .form-actions .button, .recommendation .button { width: 100%; }
  .form-hint { margin: 0; }
  .score-orbit { width: 86px; height: 86px; }
  .document-actions { width: 100%; }
  .document-actions .button { flex: 1; }
  .document-shell { margin-inline: -16px; border-radius: 0; }
  .document-page { min-height: 760px; }
  .tracker-card { grid-template-columns: 1fr; }
}

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

@media print {
  body { background: white; }
  .topbar, .sidebar, .demo-banner, .view-heading, .document-tabs, .edit-note, #letterPanel.is-hidden, #resumePanel.is-hidden { display: none !important; }
  .app-shell, .workspace, .view, .document-shell { display: block !important; margin: 0; padding: 0; background: white; }
  .view:not(#draftsView) { display: none !important; }
  .document-page { width: 100%; min-height: 0; padding: 0; box-shadow: none; }
}
