:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --paper: #fff;
  --ink: #18251f;
  --subtle: #627268;
  --border: #e0e7df;
  --strong-border: #cdd8ce;
  --sidebar: #142820;
  --sidebar-text: #9eb6a9;
  --accent: #255e47;
  --accent-hover: #1b4937;
  --mint: #e8f3e9;
  --focus: #397958;
  --red: #a73a39;
  --shadow: 0 12px 38px #14282016;
  --radius: 12px;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .62; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.8rem, 3vw, 2.35rem); line-height: 1.1; letter-spacing: -.055em; }
h2 { font-size: 1.08rem; letter-spacing: -.025em; }
h3 { font-size: .9rem; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; stroke-width: 1.65; fill: none; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.loading { min-height: 100vh; display: grid; place-items: center; color: var(--subtle); }
.loading.small { min-height: 190px; }
.number { font-variant-numeric: tabular-nums; white-space: nowrap; }

.layout { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0,1fr); }
.sidebar { min-height: 100vh; height: 100dvh; position: sticky; top: 0; display: flex; flex-direction: column; padding: 25px 16px 18px; background: var(--sidebar); color: white; z-index: 2; }
.brand { display: flex; gap: 11px; align-items: center; margin: 0 5px; color: inherit; }
.brand-mark { height: 40px; width: 40px; display: inline-grid; place-items: center; background: #c2e7ad; border-radius: 10px; color: #214630; flex: none; }
.brand-mark .icon { width: 23px; height: 23px; }
.brand strong, .brand small, .firm strong, .firm small, .sidebar-footer strong, .sidebar-footer small { display: block; }
.brand strong { letter-spacing: -.025em; font-size: 1.05rem; font-weight: 720; }
.brand small { color: #a5bcac; font-size: .71rem; margin-top: 1px; }
.firm { display: flex; align-items: center; gap: 10px; margin: 31px 1px 16px; border: 1px solid #456054; border-radius: 9px; padding: 10px; color: #f3f8f3; min-width: 0; }
.firm-icon, .user-icon { width: 32px; height: 32px; border-radius: 8px; display: inline-grid; place-items: center; flex: none; color: #d8f0d4; background: #315343; font-weight: 700; }
.firm strong { font-size: .84rem; overflow-wrap: anywhere; }
.firm small { font-size: .68rem; color: var(--sidebar-text); }
.sidebar nav { display: grid; align-content: start; gap: 3px; overflow: auto; }
.nav-link { display: flex; min-height: 40px; gap: 11px; align-items: center; padding: 8px 12px; border-radius: 8px; color: var(--sidebar-text); font-weight: 540; }
.nav-link .icon { width: 17px; height: 17px; }
.nav-link:hover, .nav-link.active { color: #edfae9; background: #2d4e3d; }
.nav-link.active { font-weight: 700; }
.sidebar-footer { display: flex; gap: 9px; align-items: center; border-top: 1px solid #3d5649; margin-top: auto; padding: 15px 2px 0; }
.sidebar-footer > div { flex: 1; min-width: 0; }
.sidebar-footer strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: .81rem; }
.sidebar-footer small { color: var(--sidebar-text); font-size: .72rem; }
.icon-button { cursor: pointer; display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; background: transparent; color: var(--subtle); border-radius: 7px; }
.icon-button:hover { background: var(--mint); color: var(--accent); }
.signout { color: #a6bbac; }
.signout:hover { color: white; background: #2e5140; }
.main-column { min-width: 0; }
.topbar { height: 64px; background: var(--paper); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 34px; }
.breadcrumb, .top-date { display: flex; gap: 10px; align-items: center; color: var(--subtle); font-size: .81rem; }
.breadcrumb strong { color: var(--ink); }
.top-date .icon { width: 15px; height: 15px; }
.mobile-menu, .drawer-close, .drawer-backdrop { display: none; }
.content { width: min(100%, 1510px); margin: auto; padding: 31px 34px 54px; }
.demo-bar, .preview-banner { min-height: 35px; padding: 7px 34px; font-size: .76rem; background: #f0eedc; color: #655e34; border-bottom: 1px solid #e9e3ca; }
.preview-banner { background: #f6e8d4; color: #6f471e; }
.preview-banner a { text-decoration: underline; margin-left: 11px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head p, .card-head p { color: var(--subtle); margin-top: 7px; font-size: .86rem; }
.head-actions, .form-actions, .inline-tools { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.head-actions { flex: 0 0 auto; }
.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap; background: var(--paper); color: var(--ink); border: 1px solid var(--strong-border); border-radius: 8px; padding: 7px 12px; font-size: .8rem; font-weight: 680; }
.button .icon { width: 16px; height: 16px; }
.button:hover { background: #f4f8f3; border-color: #b9cabc; }
.primary { background: var(--accent); border-color: var(--accent); color: white; }
.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.quiet { background: transparent; border-color: transparent; color: var(--accent); }
.danger-outline { color: var(--red); }
.text-link, .back-link { align-items: center; display: inline-flex; gap: 6px; width: fit-content; color: var(--accent); font-weight: 700; font-size: .81rem; background: transparent; border: 0; padding: 0; }
.text-link:hover, .back-link:hover { text-decoration: underline; }
.text-link .icon, .back-link .icon { width: 15px; height: 15px; }
.text-link .icon { order: 2; }
.back-link { margin-bottom: 13px; }
.notice { background: #f5f0d9; color: #635827; border: 1px solid #e9dfb8; border-radius: 8px; padding: 10px 13px; margin-bottom: 17px; }
.notice a { margin-left: 5px; }
.metrics { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 15px; margin: 0 0 21px; }
.metric, .card, .print-sheet { background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius); }
.metric { display: grid; min-width: 0; padding: 16px; gap: 5px; }
.metric-top { display: flex; gap: 6px; justify-content: space-between; align-items: center; color: var(--subtle); font-size: .81rem; font-weight: 650; }
.metric-icon { width: 32px; height: 32px; display: grid; place-items: center; flex: none; border-radius: 8px; background: var(--mint); color: var(--accent); }
.metric-icon .icon { width: 16px; height: 16px; }
.metric strong { font-size: clamp(1.1rem,2.2vw,1.66rem); line-height: 1.23; letter-spacing: -.052em; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.metric small { color: var(--subtle); font-size: .75rem; }
.card { margin-bottom: 17px; min-width: 0; overflow: hidden; }
.card-head { min-height: 65px; padding: 15px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head p { margin-top: 2px; font-size: .78rem; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; text-align: left; }
th, td { border-top: 1px solid var(--border); padding: 11px 16px; vertical-align: middle; }
th { background: #f7f9f6; color: #526359; font-weight: 700; font-size: .72rem; white-space: nowrap; }
td { font-size: .8rem; overflow-wrap: anywhere; }
td small { display: block; color: var(--subtle); margin-top: 2px; }
tbody tr:hover { background: #fafcf9; }
td strong { font-weight: 650; }
.record-link { display: inline-block; color: var(--accent); font-weight: 740; white-space: nowrap; }
.record-link:hover { text-decoration: underline; }
.badge { display: inline-block; font-size: .71rem; font-weight: 720; white-space: nowrap; padding: 3px 8px; border-radius: 20px; background: #edf0ed; color: #536159; }
.badge.paid, .badge.issued { background: #e7f4e7; color: #246044; }
.badge.partial, .badge.unpaid { background: #faf0d9; color: #795918; }
.badge.overdue, .badge.void { background: #f9e8e7; color: #943c3b; }
.empty { min-height: 180px; display: grid; align-content: center; justify-items: center; text-align: center; padding: 22px; gap: 5px; color: var(--subtle); }
.empty .icon { width: 26px; height: 26px; margin-bottom: 6px; color: var(--accent); }
.empty strong { color: var(--ink); }
.empty p { font-size: .82rem; }
.table-tools { display: flex; gap: 9px; align-items: center; padding: 13px 16px; }
.search-box { display: flex; flex: 1; align-items: center; gap: 8px; max-width: 420px; }
.search-box .icon { color: var(--subtle); }
.pager { padding: 10px 15px; color: var(--subtle); display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .8rem; border-top: 1px solid var(--border); }
.pager > div { display: flex; gap: 7px; }

label { display: grid; gap: 5px; color: #3f5146; font-weight: 650; font-size: .82rem; }
input, select, textarea { width: 100%; min-height: 38px; min-width: 0; background: white; border: 1px solid var(--strong-border); color: var(--ink); border-radius: 7px; padding: 7px 9px; }
input::placeholder, textarea::placeholder { color: #728578; }
textarea { resize: vertical; }
input[type="date"] { min-width: 140px; }
.form-card { padding: 17px 19px; }
.form-card > h2 { margin-bottom: 13px; }
.field-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 13px 17px; }
.field-grid .inline-tools { margin-top: 7px; }
.inline-tools input { width: auto; max-width: 230px; min-width: 120px; }
.inline-tools select { width: auto; min-width: 120px; max-width: 250px; }
.stack { display: grid; gap: 8px; }
.line-editor { min-width: 740px; }
.line-editor th, .line-editor td { padding: 8px; }
.line-editor td:first-child, .line-editor th:first-child { width: 31%; padding-left: 17px; }
.line-editor td:nth-child(2) { width: 10%; }
.line-editor td:nth-child(3) { width: 12%; }
.line-editor td:nth-child(4) { width: 12%; }
.line-editor td:nth-child(5), .line-editor td:nth-child(6) { width: 9%; }
.line-editor input { min-width: 58px; }
.line-code { margin-top: 4px; min-height: 30px; }
.line-footer { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; border-top: 1px solid var(--border); padding: 15px 18px; }
.totals { min-width: 225px; margin: 0; font-size: .84rem; }
.totals div { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.totals dt { color: var(--subtle); }
.totals dd { margin: 0; font-weight: 700; text-align: right; white-space: nowrap; }
.totals .grand { border-top: 1px solid var(--border); margin-top: 5px; padding-top: 6px; font-size: 1.03rem; }
.totals .grand dt { font-weight: 720; color: var(--ink); }
.balance { border-top: 1px solid var(--border); margin-top: 7px; padding-top: 4px; }
.form-actions { justify-content: flex-end; margin-top: 11px; }
.draft-action-total { display: none; }
.form-error { color: var(--red); font-size: .83rem; min-height: 0; }
.form-error:not(:empty) { margin: 8px 0; padding: 8px 10px; border: 1px solid #efcccc; border-radius: 7px; background: #fff5f4; }
.report-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.report-metrics { grid-template-columns: repeat(3,minmax(0,1fr)); }
.page-error { padding: 23px; }
.page-error p { margin: 8px 0 14px; }

.print-sheet { padding: 25px; margin-bottom: 16px; }
.document-heading, .document-parties, .document-footer { display: flex; justify-content: space-between; gap: 13px; }
.document-heading { padding-bottom: 17px; border-bottom: 1px solid var(--border); }
.document-heading h2 { margin: 6px 0 2px; font-size: 1.45rem; }
.document-heading p, .document-parties p, .document-footer p { color: var(--subtle); font-size: .8rem; }
.document-meta { text-align: right; min-width: 135px; }
.document-meta p { margin-top: 3px; }
.document-parties { padding: 16px 0; flex-wrap: wrap; }
.document-parties > div { flex: 1; min-width: 120px; }
.document-parties span { display: block; margin-bottom: 3px; font-weight: 650; color: var(--subtle); font-size: .73rem; }
.document-footer { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 14px; }
.document-footer h3 { margin-top: 5px; }
.document-footer h3:first-child { margin-top: 0; }
.multiline { white-space: pre-wrap; overflow-wrap: anywhere; }

dialog { width: min(95vw, 550px); border: 1px solid var(--border); border-radius: 13px; padding: 18px; margin: auto; color: var(--ink); background: white; box-shadow: var(--shadow); max-height: 90dvh; }
dialog::backdrop { background: #13291dcc; }
.dialog-head { display: flex; min-height: 35px; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 10px; }
.dialog-head h2 { font-size: 1.18rem; }
dialog form { display: grid; gap: 9px; }
dialog p { color: var(--subtle); }
dialog .form-error { color: var(--red); }
.readonly-details { display: grid; gap: 8px; }
.readonly-details dt { font-weight: 720; color: var(--subtle); }
.readonly-details dd { margin: 0; }
.toast { position: fixed; bottom: 17px; right: 17px; max-width: min(420px,calc(100vw - 34px)); padding: 10px 15px; background: var(--sidebar); color: white; border-radius: 9px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .15s, transform .15s; z-index: 9; box-shadow: var(--shadow); }
.toast.visible { opacity: 1; transform: none; }
.toast.error { background: #7d2729; }

.login-layout { min-height: 100dvh; display: grid; grid-template-columns: minmax(320px, .9fr) minmax(330px, 1fr); }
.login-brand { display: flex; flex-direction: column; justify-content: space-between; min-height: 100%; padding: clamp(30px,7vw,94px); color: #f8faf6; background: var(--sidebar); }
.login-head h1 { max-width: 420px; font-size: clamp(2.3rem,6vw,4.6rem); line-height: 1; }
.login-head p { margin-top: 15px; color: #b9d0c1; max-width: 240px; }
.login-form { display: grid; justify-items: center; align-items: center; padding: 24px; }
.login-form form { width: min(100%,365px); padding: 25px; border: 1px solid var(--border); border-radius: var(--radius); background: white; display: grid; gap: 11px; }
.login-form h2 { font-size: 1.57rem; }
.login-form p { color: var(--subtle); }
.login-form .form-error { color: var(--red); }
.login-form .notice { margin: 0; }
.login-form .primary { justify-content: space-between; }
.workspace-choice { width: min(95%,560px); margin: 7vh auto; background: white; border: 1px solid var(--border); border-radius: 12px; padding: 21px; display: grid; gap: 13px; }
.workspace-choice .brand small { color: var(--subtle); }
.workspace-choice > .button { width: fit-content; }
.company-choice { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.company-choice span { margin-left: auto; color: var(--subtle); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 199px minmax(0,1fr); }
  .content { padding: 25px 23px 35px; }
  .topbar, .demo-bar, .preview-banner { padding-left: 23px; padding-right: 23px; }
  .metric { padding: 12px; }
  th, td { padding: 10px; }
}
@media (max-width: 850px) {
  .page-head { flex-wrap: wrap; gap: 10px; }
  .metrics { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
  .card-head { flex-wrap: wrap; }
}
@media screen and (max-width: 760px) {
  .layout { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(280px, 86vw); height: 100dvh; min-height: 0; transform: translateX(-100%); visibility: hidden; z-index: 6; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .sidebar.mobile-open { transform: none; visibility: visible; }
  .sidebar .brand { padding-right: 42px; }
  .sidebar nav { min-height: 0; overscroll-behavior: contain; }
  .layout:has(.sidebar.mobile-open) { height: 100dvh; overflow: hidden; }
  .drawer-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 5; width: 100%; border: 0; background: #14282088; }
  .drawer-close { display: grid; position: absolute; top: 18px; right: 10px; color: var(--sidebar-text); }
  .mobile-menu { display: inline-grid; flex: none; }
  .topbar { height: 56px; justify-content: flex-start; }
  .top-date { display: none; }
  .breadcrumb { font-size: .75rem; gap: 5px; }
  .content, .topbar, .demo-bar, .preview-banner { padding-left: 12px; padding-right: 12px; }
  .content { padding-top: 17px; }
  .metrics { margin-bottom: 14px; }
  .metric-top { font-size: .74rem; }
  .metric-icon { width: 25px; height: 25px; }
  .metric strong { font-size: 1.2rem; }
  .field-grid { grid-template-columns: 1fr; gap: 9px; }
  .table-tools { flex-wrap: wrap; }
  .search-box { flex-basis: 100%; }
  .document-footer { flex-direction: column; }
  .print-sheet { padding: 13px; }
  .login-layout { grid-template-columns: minmax(0,1fr); }
  .login-brand { min-height: 230px; padding: 24px; }
  .login-head h1 { font-size: 2rem; }
  .login-head p { margin-top: 7px; }
  .button, .icon-button, .nav-link, .team-actions .button, .team-tab, .back-link, .text-link { min-height: 44px; }
  .icon-button { min-width: 44px; }
  .button { white-space: normal; }
  input:not([type="checkbox"]), select, textarea { min-height: 44px; font-size: 16px; }
  input[type="date"] { min-width: 0; }
  .page-head { align-items: stretch; }
  .head-actions:not(:empty) { width: 100%; }
  .head-actions .button { flex: 1 1 auto; }
  .permission-choice { min-height: 44px; }
  .inline-tools input, .inline-tools select { flex: 1 1 150px; width: 100%; max-width: none; }
  .line-footer { flex-wrap: wrap; }
  #draft-totals { flex: 1 1 100%; }
  #document-form > .form-actions { position: sticky; bottom: 0; z-index: 1; background: var(--bg); border-top: 1px solid var(--border); padding: 8px 0 max(8px, env(safe-area-inset-bottom)); }
  #document-form > .form-actions .primary { flex: 1 0 auto; }
  .draft-action-total { display: grid; flex: 1 1 90px; min-width: 0; overflow-wrap: anywhere; }
  .draft-action-total small { color: var(--subtle); }
  .draft-action-total strong { font-variant-numeric: tabular-nums; }
  .document-heading { flex-wrap: wrap; }
  .document-heading > div { min-width: 0; overflow-wrap: anywhere; }
  .document-meta { text-align: left; }
  .totals { min-width: 0; }
  .report-form label { flex: 1 1 140px; min-width: 0; }

}
@media screen and (max-width: 960px) {
  .responsive-table, .responsive-table tbody, .line-editor, .line-editor tbody { display: block; min-width: 0; }
  .responsive-table thead, .line-editor thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .responsive-table tbody tr, .line-editor tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
  }
  .responsive-table td, .line-editor td { min-width: 0; padding: 0; border: 0; white-space: normal; }
  .responsive-table td:first-child, .responsive-table td[data-label=""], .line-editor td:first-child { grid-column: 1 / -1; }
  .responsive-table td:not(:first-child):not([data-label=""])::before, .line-editor td:not([data-label=""])::before {
    content: attr(data-label);
    display: block;
    color: var(--subtle);
    font-size: .73rem;
    font-weight: 680;
    margin-bottom: 3px;
  }
  .responsive-table .record-link { white-space: normal; }
  .line-editor tbody td:nth-child(n) { width: auto; padding: 0; }
  .line-editor td:last-child { justify-self: end; align-self: end; }
  .line-editor input { min-width: 0; }
  .line-total { align-self: center; }
}

@media print {
  @page { size: A4; margin: 11mm; }
  html, body { color: #121212; background: white; font-size: 10pt; }
  .layout, .main-column, .content { display: block; width: 100%; padding: 0; margin: 0; }
  .content > :not(.print-sheet), .sidebar, .topbar, .demo-bar, .preview-banner, .toast, dialog { display: none !important; }
  .print-sheet { border: 0; padding: 0; margin: 0; }
  .print-sheet .table-wrap { overflow: visible; }
  .print-sheet table { table-layout: auto; }
  .print-sheet th, .print-sheet td { padding: 6px 4px; font-size: 8pt; }
  .print-sheet tr, .document-heading, .document-parties, .document-footer { break-inside: avoid; }
  .print-sheet thead { display: table-header-group; }
  .print-sheet * { print-color-adjust: exact; }
}

.team-tabs { display: flex; flex-wrap: wrap; gap: 7px 17px; padding: 10px 16px 0; }
.team-tab { display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 6px 2px 8px; border-bottom: 2px solid transparent; color: var(--subtle); font-size: .81rem; font-weight: 680; }
.team-tab:hover, .team-tab.current { color: var(--accent); }
.team-tab.current { border-bottom-color: var(--accent); }
.team-tab span { min-width: 17px; padding: 0 4px; text-align: center; border-radius: 12px; background: #eef2ed; font-size: .7rem; }
.team-actions { display: flex; gap: 0 2px; flex-wrap: wrap; align-items: center; }
.team-actions .button { min-height: 32px; padding: 4px 7px; }
.protected-label { color: var(--subtle); font-size: .76rem; }
.badge.owner { background: #e7f2e4; color: #24523b; }
.badge.active { background: #e7f4e7; color: #246044; }
.badge.suspended, .badge.expired { background: #faf0d9; color: #795918; }
.badge.archived { background: #edf0ed; color: #536159; }
.badge.invited { background: #e9f0f8; color: #37546e; }
.permissions-group { border: 1px solid var(--border); border-radius: 8px; min-width: 0; margin: 0; padding: 7px 10px 9px; }
.permissions-group legend { color: var(--ink); font-size: .78rem; font-weight: 720; padding: 0 4px; }
.permission-fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; margin-top: 3px; }
.permission-choice { display: flex; gap: 7px; align-items: center; padding: 4px 0; font-weight: 540; line-height: 1.25; }
.permission-choice input { width: 16px; min-height: 16px; height: 16px; flex: none; margin: 0; accent-color: var(--accent); }
.team-readonly { border: 0; padding: 0; margin: 0; min-width: 0; }
dialog #activation-link { margin-bottom: 9px; }
@media (max-width: 500px) { .permission-fields { grid-template-columns: minmax(0,1fr); } }
