:root {
  --ink: #14231d;
  --muted: #617169;
  --paper: #f5f3ed;
  --surface: #fffefa;
  --surface-2: #ecebe4;
  --line: #d6d9d0;
  --green: #0d654b;
  --green-2: #d9eee5;
  --mint: #a6d9c2;
  --amber: #ad6419;
  --amber-bg: #fff0d7;
  --red: #a83c35;
  --red-bg: #f9e2df;
  --blue: #355e86;
  --shadow: 0 18px 48px rgba(26, 44, 36, .1);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.2rem, 2vw, 1.55rem); letter-spacing: -.035em; }
h2 { margin-bottom: .45rem; font-size: clamp(1.35rem, 2.5vw, 2rem); letter-spacing: -.04em; }
h3 { margin-bottom: 1rem; font-size: 1rem; }
h4 { margin: 0; }

.skip-link { position: fixed; z-index: 100; top: 8px; left: 8px; transform: translateY(-160%); padding: .65rem 1rem; border-radius: 8px; background: var(--ink); color: white; }
.skip-link:focus { transform: none; }
.eyebrow { margin-bottom: .28rem; color: var(--green); font-size: .69rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); font-size: .86rem; line-height: 1.55; }

.app-header { position: sticky; z-index: 30; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 74px; padding: .75rem clamp(1rem, 3vw, 2.5rem); border-bottom: 1px solid rgba(20, 35, 29, .08); background: rgba(255, 254, 250, .94); backdrop-filter: blur(16px); }
.brand-block, .header-actions { display: flex; align-items: center; gap: .8rem; }
.brand-mark { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 13px 4px 13px 4px; background: var(--green); color: white; font-family: Georgia, serif; font-size: 1.15rem; font-style: italic; font-weight: 700; }
.project-picker { display: grid; gap: .15rem; color: var(--muted); font-size: .68rem; font-weight: 700; text-transform: uppercase; }
.project-picker select { min-width: 240px; border: 0; background: transparent; color: var(--ink); font-size: .9rem; font-weight: 700; text-transform: none; }

main { padding: 0 clamp(1rem, 3vw, 2.5rem) 4rem; }
.project-hero { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: clamp(1.65rem, 4vw, 3.4rem) 0 1.45rem; }
.project-hero h2 { font-size: clamp(1.9rem, 4.5vw, 3.65rem); max-width: 900px; line-height: 1.02; }
.hero-note { max-width: 850px; margin-bottom: 0; color: var(--muted); line-height: 1.55; }
.award-chip { display: flex; align-items: center; gap: .75rem; flex: 0 0 auto; padding: .8rem 1.05rem; border: 1px solid #b7d8c9; border-radius: 999px; background: var(--green-2); color: var(--green); }
.award-chip > span { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; background: var(--green); color: white; }
.award-chip small, .award-chip strong { display: block; }
.award-chip small { font-size: .65rem; text-transform: uppercase; }

.lifecycle { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; padding: .5rem 0 1.35rem; }
.lifecycle-stage { position: relative; display: grid; gap: .2rem; min-width: 0; padding: .75rem .8rem .8rem 2.2rem; border-top: 2px solid var(--line); color: var(--muted); }
.lifecycle-stage::before { position: absolute; top: -7px; left: 0; width: 12px; height: 12px; border: 2px solid var(--line); border-radius: 50%; background: var(--paper); content: ""; }
.lifecycle-stage strong { overflow: hidden; font-size: .82rem; text-overflow: ellipsis; white-space: nowrap; }
.lifecycle-stage small { font-size: .7rem; }
.lifecycle-stage.past { border-color: var(--green); color: var(--green); }
.lifecycle-stage.active { border-color: var(--green); color: var(--ink); }
.lifecycle-stage.past::before { border-color: var(--green); background: var(--green); }
.lifecycle-stage.active::before { top: -9px; width: 16px; height: 16px; border: 4px solid var(--green); background: var(--surface); }

.finance-strip { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 28px rgba(26, 44, 36, .05); }
.metric { min-height: 118px; padding: 1.15rem 1.25rem; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric small { display: block; margin-bottom: .45rem; color: var(--muted); font-size: .7rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.metric strong { display: block; font-size: clamp(1.35rem, 2.6vw, 2.15rem); letter-spacing: -.04em; }
.metric p { margin: .38rem 0 0; color: var(--muted); font-size: .76rem; line-height: 1.35; }
.metric.status-healthy { background: var(--green-2); }
.metric.status-compensation { background: var(--amber-bg); }
.metric.status-critical { background: var(--red-bg); }

.workspace-tabs { display: flex; gap: .25rem; overflow-x: auto; margin: 1.5rem 0 0; padding: .28rem; border-radius: 13px; background: #e8e7df; }
.workspace-tabs button { flex: 0 0 auto; padding: .72rem 1rem; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: .84rem; font-weight: 750; }
.workspace-tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 3px 12px rgba(25, 43, 35, .09); }
.view { padding-top: 1.7rem; }
.view-heading { display: flex; align-items: end; justify-content: space-between; gap: 2rem; margin-bottom: 1.25rem; }
.view-heading > p { max-width: 600px; margin-bottom: .45rem; color: var(--muted); line-height: 1.5; }

.board { display: grid; grid-template-columns: repeat(6, minmax(250px, 1fr)); gap: .75rem; overflow-x: auto; padding-bottom: 1rem; scroll-snap-type: x proximity; }
.board-column { min-height: 480px; padding: .75rem; border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 254, 250, .5); scroll-snap-align: start; }
.board-column.drag-over { outline: 3px solid var(--mint); outline-offset: -3px; }
.column-header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .2rem .1rem .8rem; }
.column-header h3 { margin: 0; }
.count { min-width: 24px; padding: .2rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .7rem; text-align: center; }
.card-list { display: grid; align-content: start; gap: .65rem; min-height: 400px; }
.work-card { padding: .9rem; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: 0 5px 16px rgba(24, 39, 33, .06); cursor: grab; }
.work-card:hover { border-color: #9eb3a8; transform: translateY(-1px); }
.work-card:focus-visible { outline: 3px solid var(--mint); }
.work-card h4 { margin: .55rem 0 .45rem; font-size: .94rem; line-height: 1.32; }
.work-card p { display: -webkit-box; overflow: hidden; margin-bottom: .65rem; color: var(--muted); font-size: .77rem; line-height: 1.45; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.card-top, .card-meta, .card-flags { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.scope-code, .mode-chip, .flag { padding: .22rem .42rem; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: .64rem; font-weight: 750; }
.scope-code { background: var(--ink); color: white; }
.mode-development { background: #e5e7f5; color: #414b89; }
.mode-adaptation { background: #e1eee9; color: var(--green); }
.mode-routine { background: #eeeae1; color: #6b5b38; }
.flag.suggested, .flag.decision { background: var(--amber-bg); color: var(--amber); }
.flag.approved { background: var(--green-2); color: var(--green); }
.card-meta { justify-content: space-between; padding-top: .6rem; border-top: 1px solid #ecece7; color: var(--muted); font-size: .7rem; }
.empty-column { padding: 1rem .4rem; color: #8a9690; font-size: .78rem; text-align: center; }

.budget-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.toolbar-actions { display: flex; align-items: center; justify-content: end; gap: .55rem; flex-wrap: wrap; }
.version-chip { padding: .45rem .65rem; border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: .73rem; font-weight: 700; }
.input-with-unit { display: flex; align-items: center; max-width: 140px; margin-top: .25rem; border: 1px solid var(--line); border-radius: 9px; background: white; }
.input-with-unit input { width: 100%; border: 0; }
.input-with-unit span { padding-right: .7rem; color: var(--muted); }
.budget-buckets { display: grid; gap: 1rem; }
.budget-bucket { overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.bucket-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem; background: #e8eee9; }
.bucket-heading h3 { margin: 0; }
.bucket-heading p { margin: .2rem 0 0; color: var(--muted); font-size: .75rem; }
.bucket-totals { display: flex; gap: 1rem; text-align: right; }
.bucket-totals span { display: grid; gap: .12rem; }
.bucket-totals small { color: var(--muted); font-size: .62rem; text-transform: uppercase; }
.bucket-totals strong { font-size: .9rem; }
.bucket-totals .warn { color: var(--amber); }
.budget-scroll { overflow-x: auto; }
.budget-table { width: 100%; min-width: 1540px; border-collapse: collapse; }
.budget-table th, .budget-table td { padding: .68rem .45rem; border-top: 1px solid #e7e8e2; text-align: right; vertical-align: top; }
.budget-table th { color: var(--muted); font-size: .64rem; font-weight: 750; letter-spacing: .025em; text-transform: uppercase; }
.budget-table th:first-child, .budget-table td:first-child { width: 250px; padding-left: 1rem; text-align: left; }
.budget-table input { width: 92px; padding: .5rem; text-align: right; }
.budget-table .wide-input { width: 180px; text-align: left; }
.budget-table .item-name { display: block; font-size: .78rem; }
.budget-table .item-code { margin-right: .35rem; color: var(--green); font-weight: 800; }
.variance-positive { color: var(--amber); font-weight: 800; }
.variance-negative { color: var(--green); font-weight: 800; }

.source-layout { display: grid; grid-template-columns: minmax(270px, .7fr) minmax(380px, 1.3fr); gap: 1rem; }
.upload-card, .panel { display: grid; gap: .8rem; padding: 1.15rem; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.document-list, .source-list { display: grid; gap: .65rem; margin-top: .8rem; }
.document-card, .source-card { padding: .9rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.document-card h4, .source-card h4 { margin: 0 0 .35rem; font-size: .86rem; }
.document-card p, .source-card p { margin: 0; color: var(--muted); font-size: .76rem; line-height: 1.5; }
.source-card.suggested { border-left: 4px solid #df9a48; }
.source-card.discarded { opacity: .58; }
.source-actions { display: flex; gap: .4rem; margin-top: .65rem; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: .7rem; }
.section-heading h3 { margin: 0; }
.section-heading span { color: var(--muted); font-size: .72rem; }
.settings-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.facts { display: grid; grid-template-columns: 1fr auto; gap: .55rem 1rem; margin: 0; font-size: .8rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; text-align: right; }
.history-panel { margin-top: 1rem; }
.history-row { display: grid; grid-template-columns: 160px 1fr 170px; gap: 1rem; padding: .75rem 0; border-top: 1px solid var(--line); font-size: .78rem; }

label { display: grid; gap: .3rem; color: #425048; font-size: .74rem; font-weight: 700; }
input, select, textarea { width: 100%; padding: .62rem .7rem; border: 1px solid var(--line); border-radius: 9px; background: white; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(13, 101, 75, .12); }
textarea { resize: vertical; line-height: 1.4; }
fieldset { margin: 1rem 0 0; padding: .8rem; border: 1px solid var(--line); border-radius: 10px; }
legend { padding: 0 .35rem; color: var(--muted); font-size: .72rem; font-weight: 700; }
.check-list { display: grid; gap: .45rem; max-height: 170px; overflow-y: auto; }
.check-list label { display: flex; align-items: start; gap: .5rem; font-weight: 500; line-height: 1.4; }
.check-list input { width: auto; margin-top: .18rem; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }

.button, .icon-button { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; border: 1px solid transparent; text-decoration: none; transition: .15s ease; }
.button { min-height: 38px; padding: .56rem .82rem; border-radius: 9px; font-size: .78rem; font-weight: 750; }
.button.primary { background: var(--green); color: white; }
.button.primary:hover { background: #084d3a; }
.button.secondary { border-color: #aec4b8; background: white; color: var(--green); }
.button.ghost { border-color: var(--line); background: transparent; color: var(--muted); }
.button.small { min-height: 31px; padding: .38rem .55rem; font-size: .7rem; }
.button.full { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: .45; }
.icon-button { width: 38px; height: 38px; padding: 0; border-radius: 50%; background: var(--surface-2); font-size: 1.1rem; }

.dialog { width: min(680px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0; border: 0; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.dialog.wide { width: min(1160px, calc(100vw - 2rem)); }
.dialog::backdrop { background: rgba(15, 27, 22, .58); backdrop-filter: blur(3px); }
.dialog-shell { padding: 1.1rem; }
.dialog-header, .dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dialog-header { padding-bottom: .9rem; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 1.35rem; }
.dialog-footer { justify-content: end; padding-top: 1rem; border-top: 1px solid var(--line); }
.dialog-grid { display: grid; grid-template-columns: .85fr 1.15fr; gap: 1.2rem; overflow-y: auto; max-height: calc(100vh - 185px); padding: 1rem 0; }
.dialog-grid section { min-width: 0; }
.dialog-grid label, #transition-form label { margin-bottom: .62rem; }
.plan-editor { padding-left: 1.2rem; border-left: 1px solid var(--line); }
.plan-steps { display: grid; gap: .5rem; margin: .65rem 0; }
.plan-step { display: grid; grid-template-columns: 1fr 82px 38px; gap: .4rem; }
.plan-step button { border: 0; border-radius: 8px; background: var(--red-bg); color: var(--red); }
.plan-actions { display: flex; gap: .45rem; flex-wrap: wrap; margin-top: .8rem; }
.ai-feedback { margin-top: .7rem; padding: .75rem; border-left: 4px solid var(--blue); border-radius: 8px; background: #eaf0f7; color: #294763; font-size: .76rem; line-height: 1.5; }

.toast-region { position: fixed; z-index: 80; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; width: min(380px, calc(100vw - 2rem)); }
.toast { padding: .8rem 1rem; border-radius: 10px; background: var(--ink); color: white; box-shadow: var(--shadow); font-size: .8rem; }
.toast.error { background: var(--red); }
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 1rem; background: radial-gradient(circle at 20% 15%, #dcebe3, transparent 34%), var(--paper); }
.login-card { width: min(420px, 100%); padding: clamp(1.4rem, 5vw, 2.2rem); border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.login-card > p { margin: 1.4rem 0; color: var(--muted); }
.login-card label { margin-bottom: .8rem; }
.form-error { padding: .65rem; border-radius: 8px; background: var(--red-bg); color: var(--red); font-size: .8rem; }

@media (max-width: 1000px) {
  .finance-strip { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .source-layout, .settings-grid { grid-template-columns: 1fr; }
  .dialog-grid { grid-template-columns: 1fr; }
  .plan-editor { padding: 1rem 0 0; border-top: 1px solid var(--line); border-left: 0; }
}

@media (max-width: 700px) {
  .app-header { align-items: flex-start; }
  .app-header .brand-block .eyebrow, .app-header .brand-block h1 { display: none; }
  .header-actions { flex: 1; justify-content: flex-end; }
  .project-picker { flex: 1; }
  .project-picker select { width: 100%; min-width: 0; }
  #add-card { padding-inline: .65rem; font-size: 0; }
  #add-card::after { content: "+ Card"; font-size: .75rem; }
  .project-hero { align-items: flex-start; padding-top: 1.5rem; }
  .award-chip { display: none; }
  .lifecycle { grid-template-columns: repeat(5, minmax(100px, 1fr)); overflow-x: auto; }
  .finance-strip { grid-template-columns: 1fr; }
  .metric { min-height: 90px; border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .view-heading, .budget-toolbar { align-items: stretch; flex-direction: column; }
  .view-heading { gap: .5rem; }
  .toolbar-actions { justify-content: stretch; }
  .toolbar-actions .button { flex: 1; }
  .two-columns { grid-template-columns: 1fr; }
  .history-row { grid-template-columns: 1fr; gap: .2rem; }
  .dialog { width: calc(100vw - 1rem); max-height: calc(100vh - 1rem); }
  .dialog-grid { max-height: calc(100vh - 175px); }
}

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