:root {
  /* Professional reference palette: edit these variables to retheme Scrooge. */
  --color-bg: #f6f5f1;
  --color-surface: #ffffff;
  --color-surface-soft: #efeee9;
  --color-text: #1f211f;
  --color-muted: #777970;
  --color-border: #deddd6;
  --color-accent: #203e36;
  --color-accent-strong: #173029;
  --color-accent-soft: #e7ece9;
  --color-success: #2f604b;
  --color-success-soft: #e8f0eb;
  --color-warning: #86691f;
  --color-warning-soft: #f6f0dc;
  --color-danger: #8a3d38;
  --color-danger-soft: #f6e8e6;
  --color-info: #4f6070;
  --color-info-soft: #e9edf0;
  --color-header: #1a1a1a;
  --sidebar-width: 248px;
  --radius-xs: 6px;
  --radius-sm: 9px;
  --radius-md: 13px;
  --shadow-photo: 0 10px 22px rgba(25, 27, 24, .08);
  --font-sans: "IBM Plex Mono", "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Playfair Display", Georgia, serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--color-bg); }
body.sc-body { margin: 0; min-height: 100vh; background: var(--color-bg); color: var(--color-text); font-family: var(--font-sans); font-size: 14px; line-height: 1.5; }
body.sc-body > nav, body.sc-body > .navbar { display: none !important; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.sc-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.sc-sidebar { position: sticky; top: 0; height: 100vh; padding: 30px 22px 22px; border-right: 1px solid var(--color-border); background: var(--color-bg); display: flex; flex-direction: column; z-index: 20; }
.sc-brand { display: flex; align-items: center; justify-content: center; margin: 0 6px 32px; padding: 2px 10px; }
.sc-brand-logo { display: block; width: 108px; height: auto; max-height: 84px; }
.sc-nav { display: flex; flex-direction: column; gap: 3px; }
.sc-nav-link, .sc-sidebar-footer a { display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px; border-radius: var(--radius-sm); color: var(--color-muted); font-weight: 500; transition: .15s ease; }
.sc-nav-link i, .sc-sidebar-footer i { width: 17px; text-align: center; font-size: 14px; }
.sc-nav-link:hover, .sc-sidebar-footer a:hover { color: var(--color-text); background: var(--color-surface-soft); }
.sc-nav-link.is-active { background: var(--color-accent); color: #fff; }
.sc-sidebar-footer { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--color-border); }
.sc-sidebar-user { padding: 0 12px 8px; color: var(--color-muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sc-main { min-width: 0; }
.sc-menu-toggle { display: none; border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); }
.sc-content { width: 100%; margin: 0; padding: 40px 34px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.page-heading h1 { margin: 0; font-family: var(--font-serif); font-weight: 500; font-size: clamp(32px, 4vw, 48px); letter-spacing: -.025em; line-height: 1; }
.page-eyebrow { margin-bottom: 9px; color: var(--color-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .2em; /*font-weight: 600;*/ }
.page-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }

.btn-sc { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 14px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-text); font-weight: 600; font-size: 13px; cursor: pointer; transition: .15s ease; }
.btn-sc:hover { border-color: #c8c7bf; background: var(--color-surface-soft); }
.btn-sc--primary { background: var(--color-accent); border-color: var(--color-accent); color: white; }
.btn-sc--primary:hover { background: var(--color-accent-strong); border-color: var(--color-accent-strong); }
.btn-sc--danger { color: var(--color-danger); }
.btn-sc--quiet { background: transparent; }
.btn-sc--small { min-height: 32px; padding: 0 10px; font-size: 12px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 26px; }
.metric { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 20px; }
.metric--link { display: block; color: inherit; text-decoration: none; transition: border-color .16s ease, background-color .16s ease; }
.metric--link:hover { color: inherit; border-color: var(--color-text); background: var(--color-surface-soft); }
.metric--link:focus-visible { outline: 2px solid var(--color-text); outline-offset: 2px; }
.metric-label { color: var(--color-muted); font-size: 12px; margin-bottom: 14px; }
.metric-value { font-family: var(--font-serif); font-size: 30px; line-height: 1; }
.metric-note { color: var(--color-muted); font-size: 11px; margin-top: 10px; }

.panel { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); margin-bottom: 18px; overflow: hidden; }
.panel-header { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--color-border); }
.panel-header h2 { margin: 0; font-size: 13px; font-weight: 700; }
.panel-body { padding: 20px; }
.panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }

.table-toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(130px, auto)); gap: 8px; padding: 12px; border-bottom: 1px solid var(--color-border); }
.input, .select, .textarea { width: 100%; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-text); outline: none; transition: .15s ease; }
.input, .select { min-height: 38px; padding: 0 11px; }
.textarea { min-height: 110px; padding: 10px 11px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: #aaa99f; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--color-accent); box-shadow: 0 0 0 3px var(--color-accent-soft); }

.table-wrap { width: 100%; overflow-x: auto; }
.sc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sc-table th { height: 43px; padding: 0 14px; text-align: left; color: var(--color-muted); background: #fbfbf8; border-bottom: 1px solid var(--color-border); font-size: 11px; font-weight: 600; white-space: nowrap; }
.sc-table td { padding: 13px 14px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.sc-table tbody tr:last-child td { border-bottom: 0; }
.sc-table tbody tr[data-href] { cursor: pointer; }
.sc-table tbody tr:hover { background: #fafaf7; }
.sc-table .cell-strong { font-weight: 600; }
.sc-table .cell-muted { color: var(--color-muted); }
.sc-table .cell-money { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sc-table .cell-total { font-weight: 700; color: var(--color-text); }
.sc-table .client-link { text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; }
.sc-table .client-link:hover { text-decoration-color: currentColor; }
.table-sort { color: var(--color-muted); }
.table-sort span { color: var(--color-text); }

.status { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 999px; background: var(--color-surface-soft); color: var(--color-muted); font-size: 11px; font-weight: 600; white-space: nowrap; }
.status--success { background: var(--color-success-soft); color: var(--color-success); }
.status--warning { background: var(--color-warning-soft); color: var(--color-warning); }
.status--danger { background: var(--color-danger-soft); color: var(--color-danger); }
.status--info { background: var(--color-info-soft); color: var(--color-info); }

.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0,1fr)); gap: 14px; }
.field { grid-column: span 6; }
.field--full { grid-column: 1 / -1; }
.field--3 { grid-column: span 3; }
.field--4 { grid-column: span 4; }
.field--8 { grid-column: span 8; }
.field label { display: block; margin: 0 0 6px; font-size: 11px; color: var(--color-muted); font-weight: 600; }
.field-help { margin-top: 5px; color: var(--color-muted); font-size: 11px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, .7fr); gap: 18px; align-items: start; }
.definition-list { display: grid; grid-template-columns: 160px 1fr; gap: 9px 20px; margin: 0; }
.definition-list dt { color: var(--color-muted); font-size: 12px; font-weight: 500; }
.definition-list dd { margin: 0; }

.document-lines { table-layout: auto; }
.document-lines th:nth-child(1), .document-lines td:nth-child(1) { min-width: 150px; width: 18%; }
.document-lines th:nth-child(2), .document-lines td:nth-child(2) { min-width: 220px; }
.document-lines th:nth-child(3), .document-lines td:nth-child(3) { width: 100px; min-width: 100px; white-space: nowrap; }
.document-lines th:nth-child(4), .document-lines td:nth-child(4) { width: 125px; min-width: 125px; white-space: nowrap; }
.document-lines th:nth-child(5), .document-lines td:nth-child(5) { width: 85px; min-width: 85px; white-space: nowrap; }
.document-lines th:nth-child(6), .document-lines td:nth-child(6) { width: 135px; min-width: 135px; white-space: nowrap; }
.document-lines th:nth-child(7), .document-lines td:nth-child(7) { width: 88px; min-width: 88px; }
.document-lines input, .document-lines select { min-width: 80px; }
.line-title { min-width: 220px; }
.document-total { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 18px; border-top: 1px solid var(--color-border); }
.document-total-actions { display: flex; align-items: center; gap: 8px; }
.total-box { width: min(100%, 330px); }
.total-row { display: flex; justify-content: space-between; gap: 20px; padding: 5px 0; color: var(--color-muted); }
.total-row--grand { margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--color-border); color: var(--color-text); font-family: var(--font-serif); font-size: 23px; font-weight: 700; }
.total-row--grand span, .total-row--grand strong { font-weight: 700; }

.flash { padding: 11px 14px; margin-bottom: 18px; border-radius: var(--radius-sm); border: 1px solid var(--color-border); background: var(--color-surface); }
.flash--success { color: var(--color-success); background: var(--color-success-soft); border-color: #cfddd3; }
.flash--error { color: var(--color-danger); background: var(--color-danger-soft); border-color: #e8ceca; }
.empty-state { padding: 32px 18px; text-align: center; color: var(--color-muted); }

.timeline { padding: 4px 18px 18px; }
.timeline-item { position: relative; display: grid; grid-template-columns: 16px 1fr; gap: 12px; padding: 15px 0; border-bottom: 1px solid var(--color-border); }
.timeline-item:last-child { border-bottom: 0; }
.timeline-dot { width: 7px; height: 7px; margin-top: 7px; border-radius: 50%; background: var(--color-accent); }
.timeline-copy > div:first-child { display: flex; gap: 8px; flex-wrap: wrap; }
.timeline-copy > div:first-child span { color: var(--color-muted); }
.timeline-copy small { display: block; color: var(--color-muted); margin-top: 4px; font-size: 11px; }
.timeline details { margin-top: 8px; }
.timeline summary { cursor: pointer; color: var(--color-muted); font-size: 11px; }
.diff-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.diff-grid pre { margin: 0; padding: 10px; overflow: auto; border-radius: var(--radius-xs); background: var(--color-surface-soft); font-size: 10px; }

.pagination-sc { display: flex; align-items: center; justify-content: flex-end; gap: 4px; padding: 13px 14px; border-top: 1px solid var(--color-border); }
.pagination-sc a, .pagination-sc span { min-width: 31px; height: 31px; display: grid; place-items: center; border-radius: var(--radius-xs); font-size: 12px; }
.pagination-sc a:hover, .pagination-sc .is-active { background: var(--color-surface-soft); }

.pdf-frame { width: 100%; aspect-ratio: 210 / 297; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: white; }

.sc-modal { position: fixed; inset: 0; z-index: 1000; display: none; align-items: center; justify-content: center; padding: 24px; }
.sc-modal.is-open { display: flex; }
.sc-modal-backdrop { position: absolute; inset: 0; background: rgba(25, 27, 24, .42); }
.sc-modal-dialog { position: relative; z-index: 1; width: min(760px, 100%); max-height: calc(100vh - 48px); overflow: auto; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: 0 24px 70px rgba(25,27,24,.18); }
.sc-modal-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--color-border); }
.sc-modal-header h2 { margin: 0; font-size: 14px; }
.sc-modal-close { width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: var(--radius-xs); background: transparent; cursor: pointer; color: var(--color-muted); }
.sc-modal-close:hover { background: var(--color-surface-soft); color: var(--color-text); }
.sc-modal-body { padding: 20px; }
body.sc-modal-open { overflow: hidden; }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sc-shell { display: block; }
  .sc-sidebar { position: fixed; left: -270px; width: 248px; transition: left .2s ease; box-shadow: 20px 0 40px rgba(0,0,0,.08); }
  .sc-shell.is-menu-open .sc-sidebar { left: 0; }
  .sc-menu-toggle { position: fixed; top: 12px; left: 12px; z-index: 40; width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: var(--radius-sm); }
  .sc-content { padding: 68px 16px 28px; }
  .page-heading { align-items: flex-start; }
  .page-heading h1 { font-size: 36px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { padding: 15px; }
  .metric-value { font-size: 24px; }
  .table-toolbar { grid-template-columns: 1fr 1fr; }
  .table-toolbar > :first-child { grid-column: 1 / -1; }
  .field, .field--3, .field--4, .field--8 { grid-column: 1 / -1; }
  .panel-grid { grid-template-columns: 1fr; }
  .sc-table .mobile-hide { display: none; }
  .definition-list { grid-template-columns: 120px 1fr; }
}
.sc-company-switch { margin: 0; }
.sc-company-switch .select { min-width: 180px; min-height: 34px; font-size: 12px; }

/* Dashboard proportions */
.dashboard-panel-grid { grid-template-columns: minmax(0, 1.8fr) minmax(280px, .7fr); }
.table-toolbar--clients { grid-template-columns: minmax(260px, 1fr) minmax(140px, 190px); }

@media (max-width: 1100px) {
  .dashboard-panel-grid { grid-template-columns: 1fr; }
}

/* Client detail */
.field--2 { grid-column: span 2; }
.panel-count { min-width: 24px; height: 24px; padding: 0 7px; display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; background: var(--color-surface-soft); color: var(--color-muted); font-size: 11px; font-weight: 600; }
.btn-sc--compact { min-height: 32px; padding: 0 10px; font-size: 11px; }
.contact-panel .panel-header { min-height: 58px; }
.contact-list { padding: 4px 0; }
.contact-card { width: 100%; display: grid; grid-template-columns: 44px minmax(0,1fr) 14px; align-items: center; gap: 12px; padding: 15px 18px; border: 0; border-bottom: 1px solid var(--color-border); background: transparent; color: var(--color-text); text-align: left; cursor: pointer; transition: background .15s ease; }
.contact-card:last-child { border-bottom: 0; }
.contact-card:hover { background: #fafaf7; }
.contact-avatar { width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; border-radius: 50%; background: var(--color-accent-soft); color: var(--color-accent); font-family: var(--font-serif); font-size: 15px; font-weight: 600; letter-spacing: .01em; }
.contact-avatar--large { width: 62px; height: 62px; font-size: 21px; }
.contact-card-copy { min-width: 0; display: block; }
.contact-card-heading { display: flex; align-items: center; gap: 7px; min-width: 0; }
.contact-card-heading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-card-role, .contact-card-email { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-card-role { margin-top: 2px; color: var(--color-muted); font-size: 11px; }
.contact-card-email { margin-top: 3px; font-size: 12px; }
.contact-card-arrow { color: var(--color-muted); font-size: 10px; }
.sc-modal-dialog--contact { width: min(600px,100%); }
.contact-detail-head { display: flex; align-items: center; gap: 15px; margin-bottom: 24px; }
.contact-detail-head h3 { margin: 0 0 3px; font-family: var(--font-serif); font-size: 24px; font-weight: 500; }
.contact-definition-list { padding-top: 18px; border-top: 1px solid var(--color-border); }

@media (max-width: 760px) {
  .field--2 { grid-column: 1 / -1; }
  .contact-card { padding: 14px 16px; }
}

/* Contact avatar editing */
.contact-avatar { overflow: hidden; }
.contact-avatar img { width: 100%; height: 100%; display: block; object-fit: cover; }
.contact-avatar-editor { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--color-border); }
.contact-avatar-input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.contact-remove-avatar { display: block; margin-top: 9px; color: var(--color-muted); font-size: 11px; cursor: pointer; }
.contact-remove-avatar input { margin-right: 6px; }
.contact-remove-avatar.is-hidden { display: none; }

/* Compact, human-readable audit trail */
.page-eyebrow-link { color: inherit; text-decoration: none; }
.page-eyebrow-link:hover { color: var(--color-text); text-decoration: underline; text-underline-offset: 3px; }
.audit-days { padding: 4px 20px 20px; }
.audit-day { padding: 14px 0 4px; border-bottom: 1px solid var(--color-border); }
.audit-day:last-child { border-bottom: 0; }
.audit-day h3 { margin: 0 0 10px; font-family: inherit; font-size: 12px; font-weight: 700; color: var(--color-text); }
.audit-list { margin: 0; padding: 0 0 0 18px; }
.audit-entry { margin: 0 0 9px; padding-left: 2px; color: var(--color-text); }
.audit-entry-main { font-size: 12px; line-height: 1.5; }
.audit-details { display: inline; margin-left: 5px; }
.audit-details > summary { display: inline; cursor: pointer; list-style: none; color: var(--color-muted); font-size: 11px; white-space: nowrap; }
.audit-details > summary::-webkit-details-marker { display: none; }
.audit-details > summary::before { content: '('; }
.audit-details > summary::after { content: ')'; }
.audit-details[open] { display: block; margin: 7px 0 2px; }
.audit-details[open] > summary { display: inline-block; margin-bottom: 6px; }
.audit-detail-card { padding: 9px 11px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-surface-subtle, var(--color-surface)); }
.audit-detail-meta { margin-bottom: 7px; color: var(--color-muted); font-size: 10px; }
.audit-change { display: grid; grid-template-columns: 38px minmax(0,1fr); gap: 8px; align-items: start; margin-top: 4px; }
.audit-change span { color: var(--color-muted); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.audit-change strong { font-weight: 500; overflow-wrap: anywhere; }
