:root {
  color-scheme: light;
  --paper: #f4f3ed;
  --white: #fffefa;
  --ink: #202523;
  --muted: #737872;
  --line: #e3e3dc;
  --green: #d3e769;
  --green-dark: #34482e;
  --coral: #d77c5a;
  --blue: #d9e7ef;
  --font: 'Trebuchet MS', 'Segoe UI', sans-serif;
  --display: Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font); font-size: 14px; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; }
.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 2; display: flex; width: 236px; flex-direction: column; background: var(--ink); color: #f7f7ef; padding: 28px 18px 20px; }
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; font-family: var(--display); font-size: 15px; font-weight: 800; }
.brand small { display: block; margin-top: 4px; color: #a8aea6; font: 600 9px var(--font); letter-spacing: 1.3px; }
.brand-mark { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 12px; background: var(--green); color: var(--ink); font: 800 19px var(--display); }
.nav-list { display: grid; gap: 6px; margin-top: 58px; }
.nav-item { display: flex; min-height: 42px; align-items: center; gap: 12px; border: 0; border-radius: 5px; background: transparent; color: #c0c5bf; padding: 0 12px; text-align: left; cursor: pointer; }
.nav-item > span { width: 20px; color: #aab39b; font-size: 17px; text-align: center; }
.nav-item:hover, .nav-item.active { background: #303733; color: white; }
.nav-item.active > span { color: var(--green); }
.nav-count { margin-left: auto; border-radius: 12px; background: var(--coral); color: white; padding: 2px 7px; font-size: 10px; }
.sidebar-foot { display: flex; align-items: center; gap: 7px; margin-top: auto; color: #aab0a9; font-size: 11px; }
.sidebar-foot #db-status { margin-left: auto; color: #e6e9e4; }
.status-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: #8eaf56; }
.main-content { min-height: 100vh; margin-left: 236px; padding: 0 48px 64px; }
.topbar { display: flex; min-height: 82px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: 1.5px; }
.welcome { margin: 0; font-size: 12px; color: #4c534d; }
.top-actions { display: flex; align-items: center; gap: 14px; }
.session-info { margin: 8px 0 0; color: #7c817a; font-size: 10px; text-align: right; }
.admin-badge { border: 1px solid #d6d8d0; border-radius: 20px; padding: 7px 12px; color: #555d54; font-size: 11px; }
.icon-button { display: inline-grid; width: 34px; height: 34px; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--ink); font-size: 18px; cursor: pointer; }
.icon-button:hover { background: white; }
.view { max-width: 1240px; margin: 0 auto; animation: rise .3s ease both; }
.page-heading { display: flex; min-height: 168px; align-items: center; justify-content: space-between; gap: 18px; }
.heading-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font: 700 29px/1.2 var(--display); letter-spacing: 0; }
h2 { margin: 0; font: 700 18px/1.3 var(--display); letter-spacing: 0; }
h3 { margin: 8px 0; font: 700 16px/1.35 var(--display); }
.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 9px; border: 0; border-radius: 4px; padding: 0 17px; text-decoration: none; cursor: pointer; font-weight: 600; transition: transform .15s ease, background .15s ease; }
.button:hover { transform: translateY(-1px); }
.button-dark { background: var(--ink); color: white; }
.button-dark:hover { background: #39423b; }
.button-light { background: #ecece5; color: var(--ink); }
.metrics { display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 12px; }
.metric { display: flex; min-height: 142px; flex-direction: column; align-items: flex-start; justify-content: center; border: 1px solid var(--line); border-radius: 5px; background: var(--white); padding: 20px 22px; }
.metric > span { color: #626a63; font-size: 12px; }
.metric strong { margin: 8px 0 5px; font: 700 27px var(--display); }
.metric small { color: var(--muted); font-size: 11px; }
.metric-ink { border-color: var(--ink); background: var(--ink); color: white; }
.metric-ink > span, .metric-ink small { color: #d1d5ce; }
.metric-ink strong { color: var(--green); }
.content-section { margin-top: 48px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 16px; }
.text-button { border: 0; background: none; color: #425b3c; padding: 8px 0; cursor: pointer; font-weight: 600; }
.text-button:hover { color: #718c3b; }
.table-wrap { overflow-x: auto; border-top: 1px solid var(--line); }
table { width: 100%; min-width: 690px; border-collapse: collapse; background: transparent; text-align: left; }
th { height: 42px; color: #7c817a; font-size: 9px; font-weight: 700; letter-spacing: 1.1px; white-space: nowrap; }
td { height: 58px; border-top: 1px solid var(--line); color: #444a45; font-size: 12px; white-space: nowrap; }
td strong { color: var(--ink); font-weight: 600; }
.align-right { text-align: right; }
.mono { font-family: 'Consolas', monospace; font-size: 11px; }
.cell-sub { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.client-actions { display: flex; justify-content: flex-end; gap: 12px; }
.status { display: inline-flex; align-items: center; border-radius: 20px; background: var(--blue); color: #385366; padding: 5px 9px; font-size: 10px; font-weight: 600; }
.status-open { background: #f5e1d9; color: #8d4934; }
.status-admin { background: #dce8bc; color: #43562f; }
.status-in_progress { background: #e6e9bd; color: #62672e; }
.status-closed { background: #e3e6df; color: #5b625b; }
.empty-state { height: 90px; color: #858a83; text-align: center; }
.request-list { display: grid; gap: 10px; }
.request-item { border-top: 1px solid var(--line); padding: 18px 4px; }
.request-item p { max-width: 760px; color: #555d56; line-height: 1.65; white-space: pre-wrap; }
.request-item > small { color: var(--muted); font-size: 11px; }
.request-meta { display: flex; align-items: center; justify-content: space-between; }
.request-meta time { color: var(--muted); font-size: 11px; }
.request-close { display: block; margin-top: 8px; }
.dialog { width: min(560px, calc(100vw - 26px)); max-height: min(88vh, 780px); overflow-y: auto; border: 1px solid #d9dad2; border-radius: 7px; background: var(--white); padding: 24px; color: var(--ink); }
.history-dialog { width: min(980px, calc(100vw - 26px)); }
.history-dialog table { min-width: 720px; }
.history-dialog td { white-space: normal; }
.template-editor { display: grid; grid-template-columns: minmax(420px, 1fr) minmax(320px, .85fr); gap: 24px; align-items: start; }
.template-controls, .template-preview-section { border: 1px solid var(--line); background: var(--white); padding: 20px; }
.template-controls h3 { margin-top: 24px; }
.template-toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.template-toggle { display: flex; align-items: center; gap: 8px; }
.template-toggle input { width: auto; }
.print-toolbar { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin: 0 0 14px; }
.print-toolbar-range { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.print-toolbar-range label { font-size: 12px; }
.select-cell { width: 34px; }
.select-cell input { width: auto; }
.template-line-section { border: 1px solid var(--line); padding: 12px; margin-bottom: 12px; }
.template-line-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.template-line-head h4 { margin: 0; }
.template-line-empty { margin: 0; color: #5e665f; font-size: .9em; }
.template-line-row { display: grid; grid-template-columns: minmax(160px, 1fr) 70px 110px auto auto; align-items: end; gap: 8px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.template-line-row textarea { min-height: 52px; resize: vertical; }
.template-line-row .template-toggle { padding-bottom: 10px; }
.template-preview-lines p { margin: 2px 0; white-space: pre-line; }
.template-preview-section { position: sticky; top: 18px; }
.template-preview { margin-top: 16px; overflow: auto; background: #e8e9e2; padding: 16px; }
.template-preview-sheet { min-height: 420px; margin: auto; border: 1px solid #babeb8; background: white; color: var(--template-text); padding: 16px; box-shadow: 0 4px 14px #0001; }
.template-preview-sheet header { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; border-bottom: 2px solid var(--template-accent); padding-bottom: 8px; }
.template-preview-sheet header div { display: grid; gap: 4px; }
.template-preview-sheet header small { font-size: .72em; }
.template-preview-bar { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 8px; }
.template-preview-bar h3 { margin: 0; font-size: 1.1em; }
.template-preview-logo { max-width: 48px; max-height: 36px; object-fit: contain; }
.template-preview-note { white-space: pre-line; text-align: center; }
.template-preview-info { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; background: var(--template-panel); padding: 8px; }
.template-preview-info p { margin: 5px 0; }
.template-preview-sheet table { min-width: 0; font-size: .8em; border-collapse: collapse; }
.template-preview-sheet th, .template-preview-sheet td { height: auto; border: 1px solid #909790; padding: 5px; color: var(--template-text); white-space: normal; }
.template-preview-sheet th { background: var(--template-accent); }
.template-preview-total { display: flex; justify-content: space-between; margin: 10px 0 0 auto; max-width: 78%; background: var(--template-accent); padding: 8px; font-weight: 700; }
.template-preview-sheet footer { margin-top: 14px; border-top: 1px solid var(--template-accent); padding-top: 8px; }
.template-preview-signature { max-width: 70%; margin: 20px auto 0; text-align: center; }
.template-preview-signature img { display: block; max-width: 100%; max-height: 50px; margin: 0 auto 4px; object-fit: contain; }
.template-preview-signature .template-preview-lines { border-top: 1px solid #333; padding-top: 4px; }
.dialog::backdrop { background: rgb(30 35 31 / 45%); backdrop-filter: blur(2px); }
.dialog-head { display: flex; align-items: start; justify-content: space-between; margin-bottom: 20px; }
.dialog-head h2 { font-size: 21px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
label { display: grid; gap: 6px; color: #565e57; font-size: 11px; font-weight: 600; }
.field-help { color: var(--muted); font-size: 10px; font-weight: 400; line-height: 1.4; }
input, select, textarea { width: 100%; min-height: 39px; border: 1px solid #d9dbd3; border-radius: 3px; outline: none; background: white; color: var(--ink); padding: 9px 10px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #788f43; box-shadow: 0 0 0 2px rgb(211 231 105 / 30%); }
.span-two { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: end; gap: 9px; margin-top: 22px; }
.person-summary { display: grid; gap: 5px; border-top: 1px solid var(--line); padding: 10px 0; color: #565e57; font-size: 11px; }
.person-summary strong { color: var(--ink); font-size: 13px; }
.payroll-net { display: flex; flex-direction: column; justify-content: center; border-top: 1px solid var(--line); padding: 8px 2px; color: var(--muted); font-size: 11px; }
.payroll-net strong { margin-top: 5px; color: var(--ink); font: 700 19px var(--display); }
.form-note { min-height: 16px; color: #8a513e; font-size: 11px; }
.toast { position: fixed; z-index: 5; right: 26px; bottom: 24px; max-width: min(420px, calc(100vw - 32px)); border-radius: 4px; background: var(--ink); color: white; padding: 14px 17px; box-shadow: 0 8px 30px rgb(0 0 0 / 16%); }
.toast-error { background: #8d4934; }
.login-screen { display: grid; min-height: 100vh; place-items: center; padding: 20px; background: radial-gradient(ellipse at 15% 85%, #dce6c0 0, transparent 30%), radial-gradient(ellipse at 88% 12%, #d8e7eb 0, transparent 28%), var(--paper); }
.login-panel { width: min(420px, 100%); padding: 30px 12px; animation: rise .45s ease both; }
.login-panel .brand-mark { margin-bottom: 38px; }
.login-panel h1 { max-width: 360px; font-size: 36px; }
.login-panel .muted { max-width: 340px; margin: 14px 0 26px; color: var(--muted); line-height: 1.6; }
.company-picker { min-height: 100vh; padding: 0 28px 60px; background: radial-gradient(ellipse at 86% 10%, #d9e7ef 0, transparent 25%), radial-gradient(ellipse at 10% 90%, #dce6c0 0, transparent 26%), var(--paper); }
.company-picker-header { display: flex; min-height: 82px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.company-picker-header .brand { color: var(--ink); }
.company-picker-account { display: flex; align-items: center; gap: 18px; color: #586058; font-size: 12px; }
.company-picker-content { width: min(740px, 100%); margin: 76px auto 0; animation: rise .3s ease both; }
.company-picker-content > .muted { margin: 10px 0 28px; line-height: 1.6; }
.company-list { display: grid; gap: 10px; margin-bottom: 18px; }
.company-option { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 20px; border: 1px solid var(--line); border-radius: 5px; background: var(--white); padding: 18px 20px; }
.company-option h2 { font-size: 17px; }
.company-option p { margin: 6px 0 0; color: var(--muted); font-size: 11px; }
.company-option-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 14px; }
.company-name { max-width: 230px; overflow: hidden; color: #596158; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.company-empty { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); padding: 20px 2px; font-size: 12px; }
.portal-body { min-height: 100vh; background: radial-gradient(ellipse at 85% 0, #e0e8cf 0, transparent 23%), var(--paper); }
.portal-shell { width: min(1020px, calc(100% - 40px)); margin: 0 auto; padding-bottom: 70px; }
.portal-header { display: flex; min-height: 78px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.portal-header .brand { color: var(--ink); }
.secure-label { display: flex; align-items: center; gap: 7px; color: #626a63; font-size: 11px; }
.portal-welcome { padding: 52px 0 25px; }
.portal-welcome h1 { font-size: 31px; }
.muted { color: var(--muted); }
.portal-summary { display: grid; grid-template-columns: 1fr auto; align-items: center; border-radius: 5px; background: var(--ink); color: white; padding: 22px 25px; }
.portal-summary span { color: #d1d5ce; }
.portal-summary strong { grid-column: 2; grid-row: 1 / span 2; color: var(--green); font: 700 27px var(--display); }
.portal-summary small { margin-top: 5px; color: #aeb5ad; font-size: 10px; }
.portal-shell .content-section { margin-top: 38px; }
.portal-form { display: grid; gap: 15px; max-width: 600px; }
.portal-form .button { justify-self: start; }
.request-section { border-top: 1px solid var(--line); padding-top: 28px; }
.invoice-edit-lines { display: grid; gap: 10px; margin: 12px 0 18px; }
.invoice-edit-line { display: grid; grid-template-columns: minmax(180px, 2fr) minmax(90px, .8fr) minmax(110px, 1fr) auto; align-items: end; gap: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.invoice-edit-line .text-button { min-height: 39px; }
@keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 900px) {
  .sidebar { width: 195px; }
  .main-content { margin-left: 195px; padding: 0 28px 50px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric-ink { grid-column: 1 / -1; }
  .template-editor { grid-template-columns: 1fr; }
  .template-preview-section { position: static; }
}

@media (max-width: 620px) {
  .sidebar { position: sticky; inset: 0 0 auto; width: auto; height: auto; padding: 10px 14px; }
  .sidebar .brand { display: none; }
  .nav-list { display: flex; justify-content: flex-start; gap: 2px; margin: 0; overflow-x: auto; }
  .nav-item { min-width: 0; min-height: 40px; flex: 0 0 auto; justify-content: center; gap: 5px; padding: 0 7px; font-size: 10px; }
  .nav-item > span { width: auto; font-size: 15px; }
  .nav-count { padding: 1px 5px; }
  .sidebar-foot { display: none; }
  .main-content { min-height: calc(100vh - 60px); margin: 0; padding: 0 17px 38px; }
  .topbar { min-height: 60px; }
  .admin-badge { font-size: 10px; }
  .company-name { display: none; }
  .top-actions { gap: 7px; }
  #change-company, #logout { min-height: 34px; padding: 0 8px; font-size: 10px; }
  .session-info { margin-top: 5px; font-size: 9px; }
  .company-picker { padding: 0 16px 40px; }
  .company-picker-header { min-height: 68px; }
  .company-picker-account { gap: 9px; font-size: 10px; }
  .company-picker-content { margin-top: 42px; }
  .company-option { align-items: flex-start; padding: 15px; }
  .company-option-actions { flex-direction: column-reverse; align-items: flex-end; gap: 5px; }
  .page-heading { min-height: 130px; align-items: end; padding: 24px 0 20px; }
  h1 { font-size: 24px; }
  h2 { font-size: 16px; }
  .page-heading .button { min-height: 38px; padding: 0 11px; font-size: 11px; }
  .metrics { gap: 8px; }
  .metric { min-height: 112px; padding: 14px; }
  .metric strong { font-size: 22px; }
  .metric-ink { min-height: 118px; }
  .content-section { margin-top: 36px; }
  .dialog { padding: 19px; }
  .invoice-edit-line { grid-template-columns: 1fr 1fr; }
  .template-controls, .template-preview-section { padding: 14px; }
  .template-toggles { grid-template-columns: 1fr; }
  .template-line-row { grid-template-columns: 1fr 1fr; }
  .template-line-row textarea { grid-column: 1 / -1; }
  .portal-shell { width: min(100% - 28px, 1020px); }
  .portal-welcome { padding-top: 38px; }
  .portal-welcome h1 { font-size: 27px; }
  .portal-summary { padding: 18px; }
  .portal-summary strong { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}