:root {
  --ink: #18211e;
  --muted: #68736f;
  --line: #dfe4e1;
  --paper: #ffffff;
  --canvas: #f3f5f2;
  --green: #1f5a47;
  --green-2: #2f745e;
  --green-soft: #e5f0eb;
  --gold: #c69245;
  --gold-soft: #f7eddd;
  --red: #a3403d;
  --red-soft: #f8e8e6;
  --shadow: 0 14px 40px rgba(24, 33, 30, .07);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-2); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar { height: 76px; padding: 0 max(24px, calc((100vw - 1240px) / 2)); display: flex; align-items: center; gap: 32px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px); }
.brand { min-width: 260px; display: flex; align-items: center; gap: 12px; color: var(--ink); }
.brand:hover { color: var(--ink); }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: var(--green); color: white; font: 700 17px/1 Georgia, serif; }
.brand strong, .brand small { display: block; }
.brand strong { font: 700 16px/1.2 Georgia, serif; letter-spacing: .02em; }
.brand small { max-width: 205px; margin-top: 3px; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar nav { height: 100%; display: flex; align-items: center; gap: 4px; }
.topbar nav a { height: 100%; padding: 0 15px; display: grid; place-items: center; position: relative; color: var(--muted); font-weight: 650; }
.topbar nav a.active, .topbar nav a:hover { color: var(--ink); }
.topbar nav a.active:after { content: ""; height: 3px; position: absolute; inset: auto 12px 0; background: var(--green); border-radius: 3px 3px 0 0; }
.quick-actions { margin-left: auto; display: flex; gap: 8px; }

.shell { max-width: 1240px; margin: 0 auto; padding: 40px 24px 80px; }
.hero, .page-head { display: flex; align-items: end; justify-content: space-between; gap: 32px; margin-bottom: 30px; }
.hero { min-height: 150px; padding: 34px 38px; color: white; background: var(--green); border-radius: 22px; overflow: hidden; position: relative; box-shadow: var(--shadow); }
.hero:after { content: ""; position: absolute; width: 360px; height: 360px; right: -130px; top: -210px; border: 70px solid rgba(255,255,255,.055); border-radius: 50%; }
.hero > * { position: relative; z-index: 1; }
.hero h1, .page-head h1 { margin: 2px 0 7px; font: 700 38px/1.08 Georgia, "Times New Roman", serif; letter-spacing: -.025em; }
.hero p { max-width: 620px; margin: 0; color: rgba(255,255,255,.74); }
.hero .eyebrow { color: #b9d8cc; }
.page-head { align-items: center; }
.page-head p { margin: 0; color: var(--muted); }
.page-head.compact { max-width: 920px; margin-left: auto; margin-right: auto; }
.page-head.detail-head { align-items: end; }
.page-head .back-link { display: inline-block; margin-bottom: 15px; color: var(--muted); font-weight: 650; }
.title-line { display: flex; align-items: center; gap: 13px; }
.title-line h1 { margin-right: 4px; }
.eyebrow { margin: 0 0 5px !important; color: var(--green-2); font-size: 11px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
h2 { margin: 2px 0 0; font: 700 22px/1.2 Georgia, "Times New Roman", serif; }

.button { min-height: 43px; padding: 10px 17px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-weight: 750; transition: .16s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: white; background: var(--green); box-shadow: 0 6px 16px rgba(31,90,71,.16); }
.hero .button.primary { color: var(--green); background: #fff; }
.button.ghost { color: var(--ink); background: white; border-color: var(--line); }
.button.danger { color: var(--red); background: white; border-color: #e9bfbb; }
.button.danger:hover { background: var(--red-soft); }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.button.small { min-height: 36px; padding: 7px 12px; font-size: 13px; }
.text-link { font-weight: 700; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; margin: 0 0 22px; }
.metric-grid.three { grid-template-columns: repeat(3, 1fr); }
.metric { min-height: 136px; padding: 23px; display: flex; flex-direction: column; justify-content: center; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(24,33,30,.035); }
.metric.featured { background: #f8fbf9; border-color: #c6dcd3; }
.metric span { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric strong { margin: 7px 0 4px; font: 700 26px/1.1 Georgia, serif; }
.metric small { color: var(--muted); font-size: 11px; }
.negative { color: var(--red) !important; }

.panel { padding: 25px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 26px rgba(24,33,30,.035); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.panel-head > a { font-size: 13px; font-weight: 750; }
.panel-head > strong { color: var(--muted); font-size: 13px; }
.budget-panel { margin-bottom: 22px; }
.budget-panel .panel-head { margin-bottom: 15px; }
.budget-panel .panel-head > strong { color: var(--ink); }
.progress { height: 11px; overflow: hidden; background: #e7ebe8; border-radius: 99px; }
.progress span { height: 100%; display: block; background: linear-gradient(90deg, var(--green), #4a8c75); border-radius: inherit; }
.budget-legend, .chart-legend { display: flex; gap: 24px; margin-top: 13px; color: var(--muted); font-size: 11px; }
.dot { width: 8px; height: 8px; display: inline-block; margin-right: 6px; background: #ccd3cf; border-radius: 50%; }
.dot.actual { background: var(--green); }
.dot.plan { background: var(--gold); }
.dot.remaining { background: #cfd6d2; }
.content-grid { display: grid; grid-template-columns: 1.16fr .84fr; gap: 22px; }
.category-bars { display: grid; gap: 19px; }
.category-row > div:first-child { display: flex; justify-content: space-between; align-items: baseline; gap: 20px; margin-bottom: 7px; }
.category-row strong { font-size: 13px; }
.category-row span { color: var(--muted); font-size: 10px; }
.dual-bar { height: 12px; position: relative; background: #f0f2f0; border-radius: 3px; }
.dual-bar i { display: block; position: absolute; left: 0; border-radius: 3px; }
.dual-bar .plan { height: 5px; top: 0; background: #d9b06d; }
.dual-bar .actual { height: 5px; bottom: 0; background: var(--green); }
.activity-list { display: grid; }
.activity-list a { padding: 12px 0; display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 12px; color: var(--ink); border-bottom: 1px solid #edf0ee; }
.activity-list a:first-child { padding-top: 0; }
.activity-list a:last-child { padding-bottom: 0; border: 0; }
.activity-list a:hover strong { color: var(--green); }
.activity-date { width: 39px; height: 39px; display: grid; place-items: center; color: var(--green); background: var(--green-soft); border-radius: 9px; font-size: 11px; font-weight: 800; }
.activity-list strong, .activity-list small { display: block; }
.activity-list small { color: var(--muted); font-size: 10px; }
.activity-list b { font-size: 12px; }
.breakdown { margin-top: 22px; padding: 18px 24px; display: grid; grid-template-columns: repeat(4,1fr); gap: 20px; background: #e8ece9; border-radius: 12px; }
.breakdown span { padding-left: 16px; border-left: 2px solid #cbd3ce; }
.breakdown small, .breakdown strong { display: block; }
.breakdown small { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.breakdown strong { margin-top: 2px; }

.flash { margin: 0 0 22px; padding: 13px 16px; border-radius: 10px; font-weight: 650; }
.flash.success { color: #205542; background: var(--green-soft); border: 1px solid #c8ded5; }
.flash.error { color: #8f3431; background: var(--red-soft); border: 1px solid #efcbc7; }
.filterbar { padding: 13px; display: flex; align-items: center; gap: 10px; background: white; border: 1px solid var(--line); border-radius: 12px; }
.filterbar select, .search { height: 43px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfa; }
.filterbar select { min-width: 190px; padding: 0 35px 0 12px; color: var(--ink); }
.search { min-width: 340px; display: flex; align-items: center; gap: 8px; padding: 0 12px; }
.search.grow { flex: 1; }
.search span { color: var(--muted); font-size: 20px; }
.search input { width: 100%; border: 0; outline: 0; background: transparent; }
.list-summary { padding: 17px 5px 13px; display: flex; gap: 26px; color: var(--muted); font-size: 12px; }
.list-summary strong { color: var(--ink); }

.table-card { overflow: hidden; background: white; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 26px rgba(24,33,30,.035); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 12px 17px; color: #7a8480; background: #f8f9f8; border-bottom: 1px solid var(--line); font-size: 10px; letter-spacing: .08em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 16px 17px; border-bottom: 1px solid #edf0ee; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfb; }
td small, .cell-title { display: block; }
td small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.cell-title { color: var(--ink); font-weight: 750; }
.cell-title:hover { color: var(--green); }
.number { text-align: right; white-space: nowrap; }
.badge { padding: 5px 8px; display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.badge:before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.success { color: #236048; background: var(--green-soft); }
.badge.warning { color: #8b601f; background: var(--gold-soft); }
.badge.info { color: #3d6078; background: #e7f0f5; }
.badge.muted { color: #6f7975; background: #eef1ef; }
.invoice-links { white-space: nowrap; }
.invoice-links a, .pdf-link { margin: 2px 4px 2px 0; padding: 4px 7px; display: inline-block; color: var(--red); background: var(--red-soft); border-radius: 5px; font-size: 10px; font-weight: 800; }
.row-action { color: var(--muted); font-weight: 900; letter-spacing: .08em; }
.muted { color: var(--muted); }

.empty { min-height: 330px; padding: 60px 25px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; background: white; border: 1px solid var(--line); border-radius: var(--radius); }
.empty-icon { width: 54px; height: 54px; display: grid; place-items: center; color: var(--green); background: var(--green-soft); border-radius: 50%; font-size: 28px; }
.empty h2 { margin-top: 17px; }
.empty p { max-width: 450px; margin: 8px 0 20px; color: var(--muted); }
.compact-empty { padding: 44px 15px; color: var(--muted); text-align: center; }

.form-card { max-width: 920px; margin: 0 auto; background: white; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.form-card.narrow { max-width: 820px; }
.form-section { padding: 28px 32px; border-bottom: 1px solid var(--line); }
.section-title { margin-bottom: 23px; display: flex; align-items: center; gap: 13px; }
.section-title > span { width: 31px; height: 31px; display: grid; place-items: center; color: var(--green); background: var(--green-soft); border-radius: 50%; font-size: 10px; font-weight: 850; }
.section-title h2 { font-size: 19px; }
.section-title p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.fields { display: grid; gap: 18px; }
.fields.two { grid-template-columns: repeat(2, 1fr); }
.fields.three { grid-template-columns: repeat(3, 1fr); }
.fields .wide { grid-column: 1 / -1; }
.field { min-width: 0; display: block; position: relative; }
.field > span, .line-total > span { margin-bottom: 7px; display: block; color: #4e5955; font-size: 11px; font-weight: 750; }
.field input, .field select, .field textarea { width: 100%; min-height: 44px; padding: 10px 12px; color: var(--ink); background: #fbfcfb; border: 1px solid #d8deda; border-radius: 8px; outline: 0; transition: .15s; }
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { background: white; border-color: #699583; box-shadow: 0 0 0 3px rgba(47,116,94,.10); }
.money-input input { padding-right: 50px; }
.money-input i { position: absolute; right: 12px; bottom: 12px; color: var(--muted); font-size: 10px; font-style: normal; font-weight: 800; }
.calculated { padding: 15px 18px; display: flex; align-items: center; justify-content: space-between; background: var(--green-soft); border-radius: 9px; }
.calculated span { color: var(--green); font-size: 12px; font-weight: 700; }
.calculated strong { font: 700 20px Georgia, serif; }
.form-actions { padding: 20px 32px; display: flex; justify-content: flex-end; gap: 10px; background: #f8f9f8; border-radius: 0 0 18px 18px; }
.form-actions.sticky { position: sticky; bottom: 0; z-index: 10; border-top: 1px solid var(--line); }
.danger-zone { margin: 25px 0 0; padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; gap: 20px; background: #faf6f5; border: 1px solid #eddad8; border-radius: 12px; }
.danger-zone strong, .danger-zone small { display: block; }
.danger-zone small { color: var(--muted); }

.order-cards { display: grid; gap: 10px; }
.order-card { padding: 18px 20px; display: grid; grid-template-columns: 64px 1fr auto 20px; align-items: center; gap: 20px; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 13px; transition: .15s; }
.order-card:hover { color: var(--ink); border-color: #b9cec5; transform: translateY(-1px); box-shadow: 0 10px 25px rgba(24,33,30,.055); }
.order-date { width: 64px; height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--green-soft); border-radius: 9px; }
.order-date strong { font: 700 21px Georgia, serif; }
.order-date span { color: var(--green); font-size: 9px; font-weight: 800; text-transform: uppercase; }
.order-main h2 { margin: 0 0 4px; font-size: 18px; }
.order-main p, .order-main > span { margin: 0; color: var(--muted); font-size: 11px; }
.order-main > span { margin-top: 6px; display: block; }
.order-total { min-width: 130px; text-align: right; }
.order-total strong, .order-total span { display: block; }
.order-total strong { margin-bottom: 5px; font-size: 16px; }
.pdf-chip { width: max-content; margin-left: auto; padding: 2px 6px; color: var(--red); background: var(--red-soft); border-radius: 4px; font-size: 9px; font-weight: 850; }
.chevron { color: #a7b0ac; font-size: 27px; }

.order-layout { display: grid; grid-template-columns: 1fr 330px; align-items: start; gap: 22px; }
.receipt-summary { position: sticky; top: 96px; }
.receipt-summary dl { margin: 23px 0; }
.receipt-summary dl div { padding: 7px 0; display: flex; justify-content: space-between; gap: 20px; }
.receipt-summary dt { color: var(--muted); }
.receipt-summary dd { margin: 0; font-weight: 700; }
.receipt-summary .total { margin-top: 9px; padding-top: 15px; border-top: 1px solid var(--line); }
.receipt-summary .total dt, .receipt-summary .total dd { color: var(--ink); font: 700 19px Georgia, serif; }
.invoice-box, .current-invoice a { padding: 12px; display: flex; align-items: center; gap: 11px; color: var(--ink); background: #faf6f5; border: 1px solid #edd6d3; border-radius: 9px; }
.invoice-box > span:nth-child(2), .current-invoice a > span:nth-child(2) { min-width: 0; flex: 1; }
.invoice-box strong, .invoice-box small, .current-invoice strong, .current-invoice small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invoice-box strong, .current-invoice strong { font-size: 11px; }
.invoice-box small, .current-invoice small { color: var(--muted); font-size: 9px; }
.pdf-icon { width: 37px; height: 37px; display: grid; place-items: center; flex: 0 0 auto; color: white; background: var(--red); border-radius: 7px; font-size: 9px; font-weight: 900; }
.invoice-missing { padding: 15px; color: var(--muted); background: #f5f6f5; border-radius: 8px; text-align: center; font-size: 11px; }
.details-list { margin-top: 22px; }
.details-list h2 { margin-bottom: 18px; }
.details-list > div { padding: 12px 0; display: grid; grid-template-columns: 160px 1fr; border-top: 1px solid var(--line); }
.details-list span { color: var(--muted); }
.details-list p { margin: 0; }
.note-panel { margin-top: 22px; }

.order-form { max-width: 1060px; }
.order-lines { display: grid; gap: 12px; }
.order-line { display: grid; grid-template-columns: 32px 1fr; gap: 11px; }
.line-number { width: 30px; height: 30px; margin-top: 28px; display: grid; place-items: center; color: var(--green); background: var(--green-soft); border-radius: 50%; font-size: 10px; font-weight: 850; }
.line-fields { padding: 14px; display: grid; grid-template-columns: minmax(240px,2fr) 90px 140px 105px 32px; align-items: end; gap: 10px; background: #f8faf8; border: 1px solid #e3e8e5; border-radius: 11px; }
.line-total { min-width: 0; padding-bottom: 10px; text-align: right; }
.line-total strong { white-space: nowrap; }
.remove-line { width: 31px; height: 31px; margin-bottom: 6px; color: #8b6b68; background: transparent; border: 0; border-radius: 50%; cursor: pointer; font-size: 22px; }
.remove-line:hover { color: var(--red); background: var(--red-soft); }
.new-part-fields { grid-column: 1 / -1; padding: 15px; display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 12px; background: var(--gold-soft); border-radius: 8px; }
.new-part-fields p { grid-column: 1 / -1; margin: 0; color: #715328; font-size: 11px; }
.new-part-fields.hidden { display: none; }
.line-note { grid-column: 1 / -1; }
.add-line { margin: 14px 0 0 43px; padding: 9px 13px; color: var(--green); background: white; border: 1px dashed #8eb3a4; border-radius: 8px; cursor: pointer; font-weight: 750; }
.order-live-total { margin-top: 22px; padding: 16px 18px; display: grid; grid-template-columns: repeat(3,1fr); gap: 15px; background: #eef3f0; border-radius: 10px; }
.order-live-total span { padding-right: 16px; border-right: 1px solid #d5dfda; }
.order-live-total span:last-child { border: 0; }
.order-live-total small, .order-live-total strong { display: block; }
.order-live-total small { color: var(--muted); font-size: 10px; }
.order-live-total strong { margin-top: 2px; font: 700 18px Georgia, serif; }
.current-invoice { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.current-invoice a { min-width: 0; flex: 1; }
.current-invoice label { color: var(--muted); font-size: 11px; }
.upload-zone { min-height: 125px; margin-bottom: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); background: #fafbfa; border: 1px dashed #aebbb5; border-radius: 11px; cursor: pointer; transition: .15s; }
.upload-zone:hover, .upload-zone.dragging { color: var(--green); background: var(--green-soft); border-color: var(--green-2); }
.upload-zone input { width: 1px; height: 1px; position: absolute; opacity: 0; }
.upload-zone strong { color: var(--ink); }
.upload-zone small { margin-top: 3px; }
.upload-icon { font-size: 24px; }

@media (max-width: 1050px) {
  .topbar { gap: 15px; }
  .brand { min-width: 190px; }
  .quick-actions .ghost { display: none; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .order-layout { grid-template-columns: 1fr; }
  .receipt-summary { position: static; }
  .line-fields { grid-template-columns: minmax(200px,2fr) 85px 130px 100px 30px; }
}

@media (max-width: 780px) {
  .topbar { height: auto; padding: 11px 16px 0; flex-wrap: wrap; }
  .brand { flex: 1; }
  .quick-actions { order: 2; }
  .topbar nav { width: 100%; height: 45px; order: 3; justify-content: space-between; overflow-x: auto; }
  .topbar nav a { padding: 0 10px; font-size: 12px; }
  .shell { padding: 25px 14px 60px; }
  .hero, .page-head { align-items: flex-start; flex-direction: column; }
  .hero { padding: 26px; }
  .hero h1, .page-head h1 { font-size: 31px; }
  .metric-grid, .metric-grid.three { grid-template-columns: 1fr 1fr; }
  .content-grid { grid-template-columns: 1fr; }
  .breakdown { grid-template-columns: 1fr 1fr; }
  .filterbar { align-items: stretch; flex-direction: column; }
  .search { min-width: 0; }
  .filterbar select { width: 100%; }
  .fields.two, .fields.three { grid-template-columns: 1fr; }
  .form-section { padding: 24px 18px; }
  .form-actions { padding: 16px 18px; }
  .line-fields { grid-template-columns: 1fr 1fr; }
  .line-part, .line-note { grid-column: 1 / -1; }
  .line-total { text-align: left; }
  .remove-line { position: absolute; right: 5px; }
  .order-line { position: relative; grid-template-columns: 1fr; }
  .line-number { display: none; }
  .new-part-fields { grid-template-columns: 1fr; }
  .add-line { margin-left: 0; }
  .order-live-total { grid-template-columns: 1fr; }
  .order-live-total span { padding: 0 0 10px; border: 0; border-bottom: 1px solid #d5dfda; }
  .current-invoice { align-items: stretch; flex-direction: column; }
  .order-card { grid-template-columns: 55px 1fr auto; gap: 12px; }
  .order-date { width: 55px; }
  .order-total { min-width: 0; }
  .chevron { display: none; }
  .head-actions { width: 100%; display: flex; gap: 8px; }
  .head-actions .button { flex: 1; }
}

@media (max-width: 520px) {
  .quick-actions { display: none; }
  .brand small { max-width: 220px; }
  .metric-grid, .metric-grid.three { grid-template-columns: 1fr; }
  .metric { min-height: 116px; }
  .breakdown { grid-template-columns: 1fr; }
  .category-row > div:first-child { align-items: flex-start; flex-direction: column; gap: 2px; }
  .list-summary { flex-wrap: wrap; }
  .line-fields { grid-template-columns: 1fr; }
  .line-part, .line-note { grid-column: auto; }
  .order-card { grid-template-columns: 48px 1fr; }
  .order-date { width: 48px; }
  .order-total { grid-column: 2; display: flex; align-items: center; gap: 8px; text-align: left; }
  .order-total .pdf-chip { margin: 0; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
  .danger-zone { align-items: stretch; flex-direction: column; }
  .details-list > div { grid-template-columns: 1fr; gap: 5px; }
}
