:root {
  --red: #c81e2a;
  --red-dark: #a91823;
  --charcoal: #333333;
  --black: #171717;
  --paper: #f7f5f0;
  --gray: #777777;
  --soft-gray: #e9e7e2;
  --line: #d8d4ce;
  --shell: #1b1a18;
  --shell-2: #23211f;
  --white: #ffffff;
  --radius: 3px;
  --shadow: 0 22px 70px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; font-family: Inter, "Helvetica Neue", Arial, sans-serif; color: var(--black); background: #f2f0eb; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, .button { cursor: pointer; }
.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; }
.eyebrow { margin: 0 0 10px; color: var(--red); font-size: 10px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; }
.subhead { margin: 8px 0 0; color: var(--gray); font-size: 14px; line-height: 1.5; }
.text-link { color: #666; font-size: 12px; text-decoration: none; }
.text-link:hover { color: var(--red); }

.app-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; min-height: 76px; padding: 0 42px; color: #ddd9d2; background: rgba(23, 23, 23, .97); border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-lockup { display: flex; align-items: center; gap: 20px; text-decoration: none; }
.brand-lockup img { width: 150px; }
.brand-lockup span { padding-left: 20px; color: #77736f; border-left: 1px solid #3a3835; font-size: 10px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; }
.app-header nav { display: flex; align-items: center; gap: 28px; }
.app-header nav a, .nav-button { color: #9f9b95; background: none; border: 0; padding: 0; font-size: 11px; font-weight: 600; letter-spacing: .1em; text-decoration: none; text-transform: uppercase; }
.app-header nav a:hover, .nav-button:hover { color: #fff; }
.app-header nav form { margin: 0; }

.page-shell { width: min(1420px, calc(100% - 80px)); margin: 0 auto; padding: 68px 0 100px; }
.narrow-page { max-width: 860px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin-bottom: 42px; }
.page-heading h1 { margin: 0; font-size: clamp(34px, 4vw, 56px); line-height: 1; letter-spacing: -.04em; font-weight: 600; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 18px; border: 1px solid transparent; border-radius: var(--radius); font-size: 10px; font-weight: 700; letter-spacing: .11em; text-decoration: none; text-transform: uppercase; }
.button-primary { color: #fff; background: var(--red); border-color: var(--red); }
.button-primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.button-dark { color: #fff; background: var(--black); border-color: var(--black); }
.button-light { color: var(--charcoal); background: #fff; border-color: #ddd9d3; }
.button-wide { width: 100%; }

.summary-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border: 1px solid #dedbd5; background: #fff; margin-bottom: 24px; }
.summary-grid article { min-height: 108px; padding: 24px; border-right: 1px solid #e6e3de; }
.summary-grid article:last-child { border-right: 0; }
.summary-grid span { display: block; margin-bottom: 14px; color: #8a8680; font-size: 9px; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.summary-grid strong { font-size: clamp(18px, 2vw, 25px); font-weight: 500; letter-spacing: -.025em; }

.archive-card, .settings-card { background: #fff; border: 1px solid #dedbd5; }
.filters { display: grid; grid-template-columns: minmax(200px, 1fr) 150px 150px 130px auto auto; align-items: end; gap: 12px; padding: 22px 24px; border-bottom: 1px solid #e6e3de; }
label { display: block; color: #6f6b66; font-size: 9px; font-weight: 700; letter-spacing: .13em; line-height: 1.4; text-transform: uppercase; }
input, select, textarea { width: 100%; margin-top: 7px; padding: 11px 12px; color: var(--charcoal); background: #faf9f7; border: 1px solid #dedbd5; border-radius: var(--radius); outline: none; font-size: 13px; font-weight: 400; letter-spacing: normal; text-transform: none; }
input:focus, select:focus, textarea:focus { border-color: rgba(200,30,42,.65); box-shadow: 0 0 0 3px rgba(200,30,42,.08); }
input[readonly] { color: #8b8781; background: #efede9; cursor: not-allowed; }
textarea { resize: vertical; line-height: 1.6; }
.filters input, .filters select { margin-top: 6px; background: #fff; }

.table-wrap { overflow-x: auto; }
.archive-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.archive-table th { padding: 15px 16px; color: #8d8983; background: #faf9f7; border-bottom: 1px solid #e8e5df; font-size: 8px; font-weight: 700; letter-spacing: .16em; text-align: left; text-transform: uppercase; }
.archive-table td { padding: 18px 16px; color: #514e4a; border-bottom: 1px solid #eeece8; font-size: 12px; }
.archive-table tr:last-child td { border-bottom: 0; }
.archive-table tbody tr:hover { background: #fcfbf9; }
.invoice-id a { color: var(--black); font-weight: 700; letter-spacing: .06em; text-decoration: none; }
.invoice-id a:hover { color: var(--red); }
.amount-cell { color: var(--black) !important; font-variant-numeric: tabular-nums; }
.status { display: inline-flex; align-items: center; min-width: 58px; justify-content: center; padding: 6px 9px; border-radius: 99px; font-size: 8px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.status-draft { color: #716d67; background: #ece9e4; }
.status-sent { color: #9b6500; background: #fff0cc; }
.status-paid { color: #207048; background: #dff2e7; }
.row-actions { display: flex; align-items: center; gap: 12px; }
.row-actions a, .row-actions button { padding: 0; color: #77736e; background: none; border: 0; font-size: 10px; text-decoration: none; }
.row-actions a:hover, .row-actions button:hover { color: var(--red); }
.row-actions form { margin: 0; }
.empty-state { padding: 70px 20px !important; color: #999 !important; text-align: center; }

.login-page { min-height: 100vh; background: var(--shell); }
.login-shell { display: grid; min-height: 100vh; place-items: center; padding: 32px; }
.login-card { width: min(430px, 100%); padding: 52px; background: var(--paper); box-shadow: var(--shadow); }
.setup-card { width: min(500px, 100%); }
.login-logo { width: 180px; margin-bottom: 54px; }
.login-card h1 { margin: 0; font-size: 39px; letter-spacing: -.04em; }
.login-intro { margin: 12px 0 32px; color: #777; font-size: 13px; line-height: 1.55; }
.stack-form { display: grid; gap: 20px; }
.settings-card { padding: 36px; }
.settings-section { margin-bottom: 22px; }
.settings-heading { padding-bottom: 24px; margin-bottom: 24px; border-bottom: 1px solid #e6e3de; }
.settings-heading h2 { margin: 0; font-size: 25px; font-weight: 550; letter-spacing: -.025em; }
.settings-heading > p:last-child { margin: 8px 0 0; color: #777; font-size: 12px; line-height: 1.55; }
.stack-form small { display: block; margin-top: 6px; color: #918d87; font-size: 10px; font-weight: 400; letter-spacing: 0; line-height: 1.5; text-transform: none; }

.flash-stack { position: fixed; z-index: 100; top: 92px; right: 24px; width: min(380px, calc(100vw - 48px)); }
.flash { margin-bottom: 8px; padding: 14px 16px; color: #214f37; background: #e4f3e9; border: 1px solid #bcdcc7; box-shadow: 0 10px 30px rgba(0,0,0,.1); font-size: 12px; }
.error-box { margin: 0 0 24px; padding: 14px 16px; color: #7f1c25; background: #f9e6e8; border: 1px solid #efc4c8; font-size: 12px; line-height: 1.5; }
.error-box p { margin: 0 0 4px; }
.error-box p:last-child { margin-bottom: 0; }

.editor-shell { display: grid; grid-template-columns: 410px minmax(850px, 1fr); min-height: calc(100vh - 76px); background: var(--shell); }
.editor-panel { position: sticky; top: 76px; height: calc(100vh - 76px); padding: 28px 30px 54px; overflow-y: auto; color: #ddd9d3; background: #1c1a18; border-right: 1px solid rgba(255,255,255,.07); }
.editor-heading { display: flex; align-items: flex-start; justify-content: space-between; padding-bottom: 25px; margin-bottom: 25px; border-bottom: 1px solid rgba(255,255,255,.07); }
.editor-heading h1 { margin: 0; color: #eeeae4; font-size: 28px; font-weight: 400; letter-spacing: .06em; }
.editor-heading .eyebrow { color: #5f5b57; }
.close-editor { color: #5d5955; font-size: 25px; font-weight: 300; line-height: 1; text-decoration: none; }
.close-editor:hover { color: var(--red); }
.form-section { padding-bottom: 24px; margin-bottom: 24px; border-bottom: 1px solid rgba(255,255,255,.07); }
.form-section h2 { margin: 0 0 17px; color: #57534f; font-size: 9px; letter-spacing: .2em; text-transform: uppercase; }
.editor-panel label { margin-bottom: 14px; color: #6d6965; }
.editor-panel input, .editor-panel select, .editor-panel textarea { color: #e3dfd9; background: rgba(255,255,255,.04); border-color: rgba(255,255,255,.1); }
.editor-panel input::placeholder, .editor-panel textarea::placeholder { color: #4f4c49; }
.editor-panel input[readonly] { color: #77736e; background: rgba(255,255,255,.02); }
.editor-panel small { display: block; margin-top: 5px; color: #4f4c48; font-size: 9px; font-weight: 400; letter-spacing: normal; text-transform: none; }
.field-grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.line-item-labels, .line-item-input { display: grid; grid-template-columns: minmax(0, 1fr) 100px 25px; gap: 8px; align-items: center; }
.line-item-labels { margin-bottom: 6px; color: #6d6965; font-size: 9px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.line-item-input { margin-bottom: 9px; }
.line-item-input input { margin: 0; }
.line-item-input input:nth-child(2) { text-align: right; font-variant-numeric: tabular-nums; }
.line-item-input button { color: #57534f; background: none; border: 0; font-size: 18px; }
.line-item-input button:hover { color: var(--red); }
.add-item { width: 100%; min-height: 37px; margin-top: 4px; color: #5f5b57; background: none; border: 1px dashed rgba(255,255,255,.12); font-size: 9px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.add-item:hover { color: var(--red); border-color: rgba(200,30,42,.55); }
.field-note { margin: 10px 0 0; color: #57534f; font-size: 10px; line-height: 1.5; }
.compact-total > div { display: flex; justify-content: space-between; align-items: baseline; padding: 15px; background: rgba(255,255,255,.03); border: 1px solid rgba(255,255,255,.06); }
.compact-total span { color: #77736e; font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.compact-total strong { color: #eeeae4; font-size: 18px; font-weight: 500; }
.editor-actions { position: sticky; bottom: -54px;
  padding: 18px 0px 42px;
  background: #1c1a18;
}
.editor-actions .button-wide {
  box-sizing: border-box;
  padding: 14px 18px;
}

.editor-actions .button-wide + .button-wide {
  margin-top: 12px;
}

.preview-stage { min-width: 0; padding: 42px 38px 90px; overflow: auto; background: #242220; }
.preview-caption { width: 816px; margin: 0 auto 16px; color: #5a5652; font-size: 9px; font-weight: 700; letter-spacing: .17em; text-transform: uppercase; }
.invoice-paper { display: flex; flex-direction: column; width: 816px; min-height: 1056px; margin: 0 auto; padding: 72px 80px 70px; color: var(--black); background: var(--paper); box-shadow: var(--shadow); }
.paper-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 48px; }
.paper-header img { width: 180px; margin-top: 3px; }
.paper-header > span { color: var(--gray); font-size: 42px; font-weight: 800; letter-spacing: -.04em; line-height: 1; }
.paper-rule { border-top: 1px solid var(--charcoal); margin-bottom: 40px; }
.paper-meta { display: flex; justify-content: space-between; margin-bottom: 52px; }
.paper-label { margin: 0 0 11px !important; color: var(--gray) !important; font-size: 9px !important; font-weight: 700 !important; letter-spacing: .18em; text-transform: uppercase; }
.paper-meta strong { display: block; margin-bottom: 5px; color: var(--charcoal); font-size: 13px; }
.paper-meta p { margin: 0; color: #555; font-size: 12px; line-height: 1.9; }
.paper-meta-right { text-align: right; }
.paper-meta-right .paper-number { margin: -4px 0 16px; color: var(--black); font-size: 20px; font-weight: 300; letter-spacing: .05em; }
.paper-bill { padding-top: 32px; margin-bottom: 48px; border-top: 1px solid var(--line); }
.paper-bill h2 { min-height: 27px; margin: 0 0 4px; font-size: 22px; font-weight: 500; letter-spacing: -.02em; }
.paper-bill > p:last-child { min-height: 18px; margin: 0; color: var(--gray); font-size: 13px; }
.paper-items { flex: 1; }
.paper-items-head, .paper-item { display: grid; grid-template-columns: 1fr 140px; gap: 16px; }
.paper-items-head { padding-bottom: 10px; border-bottom: 1px solid var(--charcoal); color: var(--gray); font-size: 9px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; }
.paper-items-head span:last-child, .paper-item span:last-child { text-align: right; }
.paper-item { padding: 14px 0; border-bottom: 1px solid #e8e4de; font-size: 14px; line-height: 1.4; }
.paper-item span:last-child { font-variant-numeric: tabular-nums; }
.paper-totals { display: flex; justify-content: flex-end; padding-top: 32px; margin-top: 32px; border-top: 1px solid var(--line); }
.paper-totals > div { width: 280px; }
.paper-totals p { display: flex; align-items: baseline; justify-content: space-between; margin: 0 0 12px; }
.paper-totals span { color: var(--gray); font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.paper-totals strong { font-size: 15px; font-weight: 400; }
.paper-totals .paper-due { padding-top: 20px; border-top: 1px solid var(--charcoal); }
.paper-totals .paper-due strong { font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.paper-footer { padding-top: 24px; margin-top: 64px; color: var(--gray); border-top: 1px solid var(--line); font-size: 11px; line-height: 1.8; }

.invoice-view-shell { min-height: calc(100vh - 76px); padding: 48px 30px 90px; background: #242220; }
.invoice-toolbar { display: flex; align-items: flex-end; justify-content: space-between; width: 816px; margin: 0 auto 20px; color: #ddd9d2; }
.invoice-toolbar h1 { display: inline-block; margin: 9px 14px 0 0; font-size: 26px; font-weight: 500; }
.invoice-toolbar .text-link { color: #77736f; }
.toolbar-actions { display: flex; gap: 8px; }
.toolbar-actions form { margin: 0; }
.archive-control { width: 816px; margin: 24px auto 0; text-align: right; }
.archive-control button { padding: 0; color: #6c6863; background: none; border: 0; font-size: 10px; text-decoration: underline; }
.archive-control button:hover { color: #d7d2ca; }

@media (max-width: 1050px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-grid article { border-bottom: 1px solid #e6e3de; }
  .filters { grid-template-columns: repeat(2, 1fr); }
  .editor-shell { grid-template-columns: 380px minmax(850px, 1fr); }
}

@media print {
  .no-print, .app-header { display: none !important; }
  body, .invoice-view-shell { background: #fff; }
  .invoice-view-shell { padding: 0; }
  .invoice-paper { width: 8.5in; min-height: 11in; margin: 0; padding: .75in .82in; box-shadow: none; }
}
