:root {
  --navy: #09101a;
  --blue: #2578ee;
  --blue-dark: #1058a2;
  --surface: #f4f8fb;
  --line: #d9e5ef;
  --text: #111827;
  --muted: #5d6b7a;
  --white: #fff;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(9, 16, 26, .12);
  --radius: 14px;
  font-family: "DM Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--surface);
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; min-height: 100vh; background: var(--surface); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid rgba(37, 120, 238, .35); outline-offset: 2px; }
::selection { background: #b9dcff; color: var(--navy); }
[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; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #153d68 0, var(--navy) 42%); }
.login-card { width: min(100%, 430px); padding: 42px; border-radius: 18px; background: var(--white); box-shadow: 0 28px 70px rgba(0, 0, 0, .28); }
.login-card > img { width: 72px; height: 72px; object-fit: contain; margin-bottom: 24px; }
h1, legend, .app-brand { font-family: "Manrope", "Segoe UI", sans-serif; }
.login-card h1 { margin: 0 0 8px; font-size: clamp(1.8rem, 5vw, 2.35rem); letter-spacing: -.03em; }
.login-card p { margin: 0; color: var(--muted); }
.login-form { display: grid; gap: 18px; margin-top: 30px; }
.field { display: grid; gap: 7px; min-width: 0; }
.field label { font-size: .85rem; font-weight: 700; color: #344054; }
input, textarea { width: 100%; border: 1px solid #b8c9d8; border-radius: 10px; background: var(--white); color: var(--text); padding: 11px 12px; transition: border-color .15s, box-shadow .15s; }
input:hover, textarea:hover { border-color: #7895ad; }
input:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 120, 238, .12); outline: 0; }
textarea { resize: vertical; }
.password-field { position: relative; }
.password-field input { padding-right: 76px; }
.password-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--blue-dark); font-size: .8rem; font-weight: 700; padding: 7px; }
.form-error { color: var(--danger) !important; font-size: .9rem; font-weight: 600; }

.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; border: 0; border-radius: 10px; padding: 10px 17px; font-weight: 700; transition: transform .15s, background .15s, border-color .15s; }
.button:hover { transform: translateY(-1px); }
.button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.button--primary { background: var(--blue); color: var(--white); box-shadow: 0 8px 20px rgba(37, 120, 238, .2); }
.button--primary:hover { background: #1569db; }
.button--secondary { background: #eaf3ff; color: #0b58ad; border: 1px solid #bed9f6; }
.button--quiet { min-height: 38px; background: transparent; border: 1px solid #b8c9d8; color: #344054; }

.app-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .98); position: sticky; top: 0; z-index: 30; }
.app-brand { display: inline-flex; align-items: center; gap: 11px; color: var(--navy); font-weight: 800; text-decoration: none; }
.app-brand img { width: 42px; height: 42px; object-fit: contain; }
.app-header__actions { display: flex; align-items: center; gap: 14px; }
.session-name { color: var(--muted); font-size: .9rem; }
.app-shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: calc(100vh - 72px); }
.sidebar { position: sticky; top: 72px; height: calc(100vh - 72px); display: flex; flex-direction: column; padding: 24px 16px; border-right: 1px solid var(--line); background: var(--white); z-index: 20; }
.sidebar nav { display: grid; gap: 5px; }
.nav-item { width: 100%; min-height: 45px; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 0; border-radius: 10px; background: transparent; color: #435466; font-weight: 700; text-align: left; }
.nav-item:hover { background: #f0f5f9; color: var(--navy); }
.nav-item.is-active { background: #e8f2ff; color: #0b58ad; }
.nav-item svg, .icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar__new { width: 100%; margin-top: auto; }
.storage-note { margin: 12px 0 0; color: var(--muted); font-size: .72rem; text-align: center; }
.content { min-width: 0; padding: 38px clamp(22px, 4vw, 52px) 80px; }
.page { width: min(1320px, 100%); margin: 0 auto; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 28px; }
.page-heading h1 { margin: 0 0 6px; font: 800 2rem "Manrope", sans-serif; letter-spacing: -.035em; }
.page-heading p { margin: 0; color: var(--muted); }
.heading-actions { display: flex; gap: 10px; }
.back-button, .text-button { border: 0; background: transparent; color: var(--blue-dark); padding: 0; font-weight: 700; }
.back-button { margin-bottom: 10px; }
.mobile-menu-button { display: none; }
.icon-button { width: 42px; height: 42px; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--navy); }
.workspace { width: min(1500px, 100%); margin: 0 auto; }
.workspace__heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 30px; }
.workspace__heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 30px; }
.workspace__heading h1 { margin: 0 0 6px; font-size: clamp(2rem, 4vw, 3rem); letter-spacing: -.04em; }
.workspace__heading p { margin: 0; color: var(--muted); }
.editor-layout { display: grid; grid-template-columns: minmax(460px, .9fr) minmax(520px, 1.1fr); gap: 30px; align-items: start; }
.budget-editor { display: grid; gap: 18px; }
fieldset { min-width: 0; margin: 0; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); box-shadow: 0 4px 16px rgba(9, 16, 26, .045); }
legend { padding: 0 6px; font-weight: 800; color: var(--navy); }
.fieldset-heading { display: flex; justify-content: flex-end; align-items: center; margin: -10px 0 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field--wide { grid-column: 1 / -1; }
.items { display: grid; gap: 12px; clear: both; }
.item-row { display: grid; gap: 12px; padding: 14px; border-radius: 12px; background: #f6f9fc; border: 1px solid #e1eaf2; }
.item-row__top { display: grid; grid-template-columns: 34px minmax(0, 1fr) 40px; gap: 10px; align-items: center; }
.item-row__values { display: grid; grid-template-columns: minmax(140px, 1fr) 100px minmax(120px, auto); gap: 12px; align-items: end; padding-left: 44px; }
.item-index { align-self: center; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--navy); color: var(--white); font-weight: 800; font-variant-numeric: tabular-nums; }
.money-input { display: flex; align-items: center; border: 1px solid #b8c9d8; border-radius: 10px; background: var(--white); overflow: hidden; }
.money-input:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 120, 238, .12); }
.money-input span { padding-left: 10px; color: var(--muted); font-weight: 600; }
.money-input input { border: 0; box-shadow: none; padding-left: 5px; }
.item-subtotal { display: grid; gap: 7px; align-self: center; }
.item-subtotal span { font-size: .78rem; color: var(--muted); }
.item-subtotal strong { font-variant-numeric: tabular-nums; }
.remove-item { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 9px; background: transparent; color: #8b1a12; }
.remove-item:hover { background: #feecea; }
.remove-item svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.editor-total { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 20px 22px; border-radius: var(--radius); background: var(--navy); color: var(--white); }
.editor-total strong { font: 800 1.6rem "Manrope", sans-serif; font-variant-numeric: tabular-nums; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.metric { min-height: 148px; display: flex; flex-direction: column; justify-content: space-between; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); }
.metric--primary { color: var(--white); background: var(--navy); border-color: var(--navy); }
.metric span { color: var(--muted); font-weight: 700; font-size: .84rem; }
.metric--primary span, .metric--primary small { color: #bfd0e0; }
.metric strong { font: 800 1.65rem "Manrope", sans-serif; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.metric small { color: var(--muted); }
.dashboard-grid, .split-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.panel { margin: 0; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); box-shadow: 0 4px 16px rgba(9, 16, 26, .035); }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel h2, .panel-heading h2 { margin: 0 0 4px; font: 800 1.08rem "Manrope", sans-serif; }
.panel-heading p { margin: 0; color: var(--muted); font-size: .86rem; }
.record-list { display: grid; }
.record { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 13px 0; border-top: 1px solid #edf1f4; }
.record:first-child { border-top: 0; }
.record strong, .record span { display: block; }
.record small { color: var(--muted); }
.record__value { text-align: right; font-variant-numeric: tabular-nums; }
.record__actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 7px; }
.mini-button { min-height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; background: var(--white); color: #344054; font-size: .78rem; font-weight: 700; }
.mini-button:hover { border-color: #8aa5bc; }
.mini-button--danger { color: var(--danger); }
.empty-inline { padding: 30px 10px; color: var(--muted); text-align: center; }
.toolbar { display: flex; gap: 12px; justify-content: space-between; margin-bottom: 14px; }
.toolbar select, select { min-height: 44px; border: 1px solid #b8c9d8; border-radius: 10px; padding: 8px 34px 8px 12px; background: var(--white); color: var(--text); font: inherit; }
.search-field { position: relative; width: min(420px, 100%); }
.search-field svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 19px; height: 19px; fill: none; stroke: var(--muted); stroke-width: 2; }
.search-field input { padding-left: 40px; }
.table-panel { padding: 0; overflow: hidden; }
.responsive-table { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 15px 18px; border-bottom: 1px solid #e8eef3; text-align: left; white-space: nowrap; }
.data-table th { background: #f7f9fb; color: #536577; font-size: .75rem; letter-spacing: .04em; text-transform: uppercase; }
.data-table td:nth-child(2) { width: 100%; white-space: normal; font-weight: 700; }
.data-table tr:last-child td { border-bottom: 0; }
.status { display: inline-flex; padding: 5px 9px; border-radius: 999px; font-size: .74rem; font-weight: 800; }
.status--draft { background: #eef1f4; color: #53606c; }
.status--sent { background: #e7f1ff; color: #1559a0; }
.status--approved { background: #e8f7ec; color: #19743a; }
.status--declined { background: #feeceb; color: #9d261e; }
.empty-state { padding: 56px 20px; text-align: center; }
.empty-state h3 { margin: 0 0 5px; }
.empty-state p { margin: 0 0 18px; color: var(--muted); }
.entry-form { display: grid; gap: 16px; }
.entry-form > .button { justify-self: start; }
.cash-summary { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); overflow: hidden; }
.cash-summary div { padding: 20px 24px; border-left: 1px solid var(--line); }
.cash-summary div:first-child { border-left: 0; }
.cash-summary span, .cash-summary strong { display: block; }
.cash-summary span { color: var(--muted); font-size: .83rem; font-weight: 700; margin-bottom: 5px; }
.cash-summary strong { font: 800 1.4rem "Manrope", sans-serif; font-variant-numeric: tabular-nums; }
.positive { color: #19743a; }
.negative { color: #b42318; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 360px; padding: 13px 17px; border-radius: 10px; background: var(--navy); color: var(--white); box-shadow: var(--shadow); font-weight: 700; }

.preview-panel { position: sticky; top: 96px; min-width: 0; }
.preview-panel__label { margin-bottom: 9px; color: var(--muted); font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.budget-document { width: 100%; aspect-ratio: 210 / 297; background: var(--white); box-shadow: var(--shadow); overflow: hidden; color: #303234; font-family: "DM Sans", sans-serif; }
.document-header { position: relative; height: 19.5%; padding: 5.2% 7.5% 0; background: #e5e5e5; overflow: hidden; }
.document-brand { position: relative; z-index: 2; display: grid; justify-items: start; gap: 1.3%; }
.document-brand img { width: 29%; height: auto; max-height: 70px; object-fit: contain; object-position: left center; }
.document-brand strong { color: var(--blue); font-size: clamp(.55rem, 1.05vw, 1rem); font-family: "Manrope", sans-serif; }
.document-pattern { position: absolute; right: -4%; top: -32%; width: 52%; height: 85%; opacity: .28; background: radial-gradient(ellipse at 50% 100%, transparent 54%, #777 55%, #777 57%, transparent 58%) 0 0 / 42% 100%; }
.document-contact { position: absolute; left: 0; bottom: 0; width: 50%; height: 21%; display: flex; align-items: center; gap: 2%; padding-left: 6.8%; background: var(--blue); color: var(--white); clip-path: polygon(0 0, 91% 0, 100% 50%, 91% 100%, 0 100%); font-size: clamp(.7rem, 1.8vw, 1.45rem); }
.document-contact svg { width: 1.2em; height: 1.2em; fill: currentColor; flex: none; }
.document-date { position: absolute; right: 10%; bottom: 4%; margin: 0; color: #303234; font-size: clamp(.55rem, 1.15vw, 1rem); }
.document-body { padding: 3.4% 7.5% 5%; }
.document-meta { min-height: 31px; display: flex; align-items: baseline; justify-content: space-between; gap: 15px; }
.document-meta h2 { margin: 0 0 1.3%; font: 800 clamp(.58rem, 1.15vw, 1rem) "Manrope", sans-serif; text-transform: uppercase; }
.document-meta p { margin: 0; color: var(--muted); font-size: clamp(.44rem, .72vw, .7rem); }
.budget-document table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: clamp(.48rem, .83vw, .76rem); }
.budget-document th { padding: 1.5% 1.3%; background: #e4e4e4; text-align: left; font-weight: 800; }
.budget-document th:first-child { width: 8%; color: var(--white); background: var(--blue); }
.budget-document th:nth-child(2) { width: 48%; color: var(--white); background: var(--blue); clip-path: polygon(0 0, 92% 0, 100% 50%, 92% 100%, 0 100%); }
.budget-document th:nth-child(3) { width: 16%; }
.budget-document th:nth-child(4) { width: 10%; text-align: center; }
.budget-document th:nth-child(5) { width: 18%; }
.budget-document td { padding: 1.7% 1.3%; vertical-align: top; border-bottom: 1px solid #aaa; line-height: 1.3; overflow-wrap: anywhere; }
.budget-document td:first-child { text-align: center; font-weight: 700; font-size: 1.1em; background: #edf0ee; }
.budget-document td:nth-child(3), .budget-document td:nth-child(5) { background: #edf0ee; font-variant-numeric: tabular-nums; }
.budget-document td:nth-child(4) { text-align: center; }
.document-footer { display: grid; grid-template-columns: 1fr 43%; gap: 5%; align-items: end; margin-top: 2.2%; }
.document-terms { font-size: clamp(.48rem, .85vw, .78rem); }
.document-terms p { margin: .4em 0 0; white-space: pre-line; }
.document-terms > p::before { content: "– "; }
.document-notes { margin-top: 1em; }
.document-notes p { margin: .3em 0 0; }
.document-total { width: 100%; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 7%; padding: 2.5% 10% 2.5% 5%; color: var(--white); background: var(--blue); clip-path: polygon(0 0, 90% 0, 100% 50%, 90% 100%, 0 100%); white-space: nowrap; }
.document-total strong { font-size: clamp(.65rem, 1.35vw, 1.2rem); font-variant-numeric: tabular-nums; }

@media (max-width: 1180px) {
  .editor-layout { grid-template-columns: 1fr; }
  .preview-panel { position: static; max-width: 760px; width: 100%; margin: 0 auto; }
  .metrics { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .login-card { padding: 30px 24px; }
  .session-name { display: none; }
  .app-header { padding-inline: 14px; }
  .mobile-menu-button { display: grid; }
  .app-brand span { display: none; }
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 72px auto 0 0; width: min(280px, 84vw); height: calc(100vh - 72px); transform: translateX(-105%); transition: transform .2s ease-out; box-shadow: 18px 0 40px rgba(9,16,26,.15); }
  .sidebar.is-open { transform: translateX(0); }
  .content { padding: 26px 18px 64px; }
  .page-heading, .editor-heading { align-items: stretch; flex-direction: column; }
  .page-heading > .button, .heading-actions, .heading-actions .button { width: 100%; }
  .heading-actions { display: grid; grid-template-columns: 1fr; }
  .metrics, .dashboard-grid, .split-layout, .cash-summary { grid-template-columns: 1fr; }
  .metric { min-height: 128px; }
  .cash-summary div, .cash-summary div:first-child { border-left: 0; border-top: 1px solid var(--line); }
  .cash-summary div:first-child { border-top: 0; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar select, .search-field { width: 100%; }
  .workspace { padding-top: 26px; }
  .workspace__heading { align-items: stretch; flex-direction: column; }
  .workspace__heading .button { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .field--wide { grid-column: auto; }
  .item-row__values { grid-template-columns: 1fr; padding-left: 44px; }
  .fieldset-heading { align-items: stretch; flex-direction: column; gap: 14px; }
  .fieldset-heading .button { width: 100%; }
  .editor-total { align-items: flex-start; flex-direction: column; }
}

@page { size: A4 portrait; margin: 0; }
@media print {
  html, body { width: 210mm; height: 297mm; background: white; }
  .app-header, .sidebar, .page-heading, .budget-editor, .preview-panel__label, .toast { display: none !important; }
  .admin-view, .app-shell, .content, .page[data-page="budget-editor"], .editor-layout, .preview-panel { display: block !important; margin: 0; padding: 0; width: auto; max-width: none; }
  .page:not([data-page="budget-editor"]) { display: none !important; }
  .budget-document { width: 210mm; height: 297mm; box-shadow: none; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .document-brand strong { font-size: 11pt; }
  .document-contact { font-size: 17pt; }
  .document-date, .document-meta h2 { font-size: 11pt; }
  .document-meta p { font-size: 7.5pt; }
  .budget-document table, .document-terms { font-size: 8.5pt; }
  .document-total strong { font-size: 13pt; }
}
