:root {
  color-scheme: light;
  --ink: #181817;
  --charcoal: #343432;
  --muted: #6e6e69;
  --line: #c8c8c1;
  --paper: #fdfdfb;
  --canvas: #e8e8e3;
  --panel: #f5f5f1;
  --focus: #4a4a45;
  --radius: 0;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--canvas); }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--canvas);
}

button, input, select, textarea { font: inherit; }
button, label[for="importInput"] { -webkit-tap-highlight-color: transparent; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 72px;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgb(24 24 23 / 96%);
  color: #f6f6f2;
  border-bottom: 1px solid #3a3a37;
  backdrop-filter: blur(12px);
}

.app-header h1 { margin: 2px 0 0; font-size: 20px; letter-spacing: -0.025em; }
.app-kicker { margin: 0; color: #aaa9a2; font-size: 10px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.save-status { margin-right: 8px; color: #aaa9a2; font-size: 12px; }

.button {
  min-height: 38px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #55554f;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition: transform 160ms ease, background-color 160ms ease, color 160ms ease;
}

.button:hover { background: #33332f; }
.button:active { transform: translateY(1px); }
.button-secondary { color: #f6f6f2; background: transparent; }
.button-primary { color: #181817; background: #f6f6f2; border-color: #f6f6f2; }
.button-primary:hover { color: #f6f6f2; background: #181817; }

.workspace {
  width: min(1520px, 100%);
  min-height: calc(100dvh - 72px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
}

.editor {
  height: calc(100dvh - 72px);
  overflow-y: auto;
  padding: 28px 24px 64px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.editor-intro { padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.editor-intro h2 { margin: 0; font-size: 24px; letter-spacing: -0.035em; }
.editor-intro p { max-width: 38ch; margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.form-section { padding: 26px 0; border-bottom: 1px solid var(--line); }
.form-section h3 { margin: 0 0 18px; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; }
.section-heading-row { display: flex; justify-content: space-between; align-items: baseline; }
.field-grid { display: grid; gap: 15px; }
.field-grid.two-columns { grid-template-columns: 1fr 1fr; }

label:not(.button) { display: grid; gap: 7px; }
label:not(.button) > span { color: #555550; font-size: 11px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bdbdb6;
  border-radius: var(--radius);
  outline: none;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 2px rgb(74 74 69 / 18%); }
input:invalid { border-color: #8c3d3d; }

.line-items { display: grid; gap: 12px; }
.line-item {
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 12px;
  background: #ebebe6;
  border-left: 2px solid var(--ink);
}
.line-item .wide { grid-column: 1 / -1; }
.line-item-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.text-button, .remove-button, .reset-button { padding: 0; color: var(--ink); background: none; border: 0; cursor: pointer; font-size: 12px; font-weight: 700; }
.text-button:hover, .remove-button:hover, .reset-button:hover { text-decoration: underline; }
.remove-button { color: #7a3434; }
.reset-button { margin-top: 24px; color: var(--muted); }

.preview-stage { min-width: 0; padding: 22px; overflow: auto; }
.preview-toolbar { width: min(794px, 100%); margin: 0 auto 12px; display: flex; justify-content: space-between; color: #5d5d58; font-size: 11px; font-weight: 700; }
.paper-wrap { width: 794px; margin: 0 auto; }

.invoice-paper {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  padding: 15mm 16mm 13mm;
  overflow: hidden;
  color: var(--charcoal);
  background: var(--paper);
  box-shadow: 0 22px 65px rgb(42 42 38 / 16%);
  font-family: Arial, Helvetica, sans-serif;
}

.invoice-masthead { height: 38mm; display: grid; place-items: start center; border-bottom: 1px solid var(--ink); }
.invoice-masthead img { width: 52mm; height: 23mm; object-fit: contain; }
.invoice-title { padding: 8mm 0 11mm; text-align: center; }
.invoice-title h2 { margin: 0; color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 29px; font-weight: 400; letter-spacing: 0.01em; }
.invoice-title p { margin: 4mm 0 0; color: var(--muted); font-size: 9px; font-weight: 700; }

.invoice-parties { min-height: 48mm; display: grid; grid-template-columns: 1fr 1fr; gap: 28mm; }
.invoice-meta { display: grid; align-content: start; gap: 8mm; }
.invoice-meta > div, .invoice-client { display: grid; gap: 2.2mm; }
.invoice-client strong { color: var(--ink); font-size: 11px; }
.invoice-client span:not(.invoice-label) { font-size: 9px; }
.invoice-client b { font-weight: 400; }
.invoice-label { color: var(--muted); font-size: 7px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.invoice-meta strong, .invoice-meta div > span:last-child { color: var(--ink); font-size: 10px; font-weight: 400; }

.invoice-services { border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
.invoice-table-head, .invoice-row { display: grid; grid-template-columns: 29% 46% 25%; align-items: start; }
.invoice-table-head { padding: 4mm 0 3.5mm; color: var(--muted); border-bottom: 1px solid var(--line); font-size: 7px; font-weight: 700; text-transform: uppercase; }
.invoice-table-head span:last-child, .invoice-row .line-amount { text-align: right; }
.invoice-table-head b { font-weight: inherit; }
.invoice-row { min-height: 27mm; padding: 8mm 0 6mm; color: var(--charcoal); font-size: 9.5px; line-height: 1.5; }
.invoice-row strong { color: var(--ink); font-size: 10px; }
.line-amount { font-weight: 700; }

.invoice-totals { width: 38%; margin: 7mm 0 0 auto; display: grid; gap: 4mm; font-size: 9px; }
.invoice-totals > div { display: flex; justify-content: space-between; gap: 8mm; }
.invoice-totals span { color: var(--muted); }
.invoice-totals strong { color: var(--ink); white-space: nowrap; }
.invoice-totals .grand-total { padding-top: 4mm; border-top: 1px solid var(--line); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.invoice-totals .grand-total span { color: var(--ink); }

.invoice-watermark { position: absolute; z-index: 0; top: 125mm; left: 50%; width: 116mm; transform: translate(-50%, -50%); opacity: 0.045; pointer-events: none; }
.invoice-services, .invoice-totals, .payment-section { position: relative; z-index: 1; }

.payment-section { margin-top: 17mm; }
.payment-section h3 { margin: 0; padding-bottom: 4mm; color: var(--ink); border-bottom: 1px solid var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 18px; font-weight: 400; }
.payment-grid { padding-top: 8mm; display: grid; grid-template-columns: 1fr 1fr; gap: 28mm; }
.payment-column { display: grid; gap: 7mm; }
.payment-column > div { display: grid; gap: 2.4mm; }
.payment-column strong { color: var(--ink); font-size: 9.5px; font-weight: 400; }
.preserve-lines { white-space: pre-line; line-height: 1.5; }

.invoice-footer { position: absolute; right: 16mm; bottom: 13mm; left: 16mm; padding-top: 5mm; display: grid; grid-template-columns: 1.2fr 1fr; gap: 10mm; border-top: 1px solid var(--ink); }
.invoice-footer > div { display: grid; gap: 2.5mm; }
.invoice-footer > div:last-child { text-align: right; }
.invoice-footer strong { color: var(--ink); font-size: 8px; }
.invoice-footer span { color: var(--muted); font-size: 7px; line-height: 1.4; }
.invoice-footer span b { font-weight: 400; }

/*
 * Print master
 * These measurements use PDF points, not CSS pixels. They mirror the approved
 * ReportLab invoice so Chrome prints the same type scale and page rhythm.
 */
.invoice-paper {
  width: 595pt;
  min-height: 842pt;
  height: 842pt;
  padding: 0 52pt;
}

.invoice-masthead {
  height: 112pt;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.invoice-masthead img {
  width: 158pt;
  height: 64pt;
  margin-top: 27pt;
}

.invoice-title {
  height: 99pt;
  padding: 26pt 0 0;
}

.invoice-title h2 { font-size: 26pt; line-height: 1.12; }
.invoice-title p { margin-top: 8pt; font-size: 7.8pt; }

.invoice-parties {
  height: 106pt;
  min-height: 0;
  grid-template-columns: 208pt 1fr;
  gap: 56pt;
}

.invoice-meta { gap: 24pt; }
.invoice-meta > div, .invoice-client { gap: 5pt; }
.invoice-label { font-size: 6.8pt; }
.invoice-meta strong, .invoice-meta div > span:last-child { font-size: 10pt; }
.invoice-client strong { font-size: 10pt; }
.invoice-client span:not(.invoice-label) { font-size: 8.8pt; }

.invoice-table-head {
  height: 29pt;
  padding: 10pt 0 0;
  font-size: 6.8pt;
}

.invoice-table-head, .invoice-row { grid-template-columns: 32.4% 42.6% 25%; }

.invoice-row {
  min-height: 58pt;
  padding: 17pt 0 11pt;
  font-size: 9.4pt;
  line-height: 1.55;
}

.invoice-row strong { font-size: 10pt; }
.invoice-row > span:nth-child(2) { max-width: 145pt; }

.invoice-totals {
  width: 38%;
  margin-top: 18pt;
  gap: 11pt;
  font-size: 8.5pt;
}

.invoice-totals .grand-total {
  padding-top: 11pt;
  font-size: 9.5pt;
}

.invoice-watermark {
  top: 421pt;
  width: 410pt;
  opacity: 0.055;
}

.payment-section { margin-top: 34pt; }
.payment-section h3 { padding-bottom: 12pt; font-size: 15pt; line-height: 1.15; }
.payment-grid { padding-top: 25pt; gap: 56pt; }
.payment-column { gap: 21pt; }
.payment-column > div { gap: 6pt; }
.payment-column strong { font-size: 9.2pt; }

.invoice-footer {
  right: 52pt;
  bottom: 52pt;
  left: 52pt;
  height: 57pt;
  padding-top: 15pt;
  gap: 28pt;
}

.invoice-footer > div { gap: 6pt; }
.invoice-footer strong { font-size: 8.2pt; }
.invoice-footer span { font-size: 7.7pt; line-height: 1.35; }

/* Premium application shell. Invoice rules above remain the print authority. */
:root {
  --app-bg: #0d0e0e;
  --app-surface: #141515;
  --app-elevated: #1a1b1b;
  --app-field: #202121;
  --app-line: #303232;
  --app-line-strong: #464848;
  --app-text: #f1f1ed;
  --app-muted: #a2a49f;
  --app-faint: #8f928c;
  --app-highlight: #dfe0da;
  --control-radius: 12px;
  accent-color: var(--app-highlight);
}

html {
  background: var(--app-bg);
  scrollbar-color: #4b4d4b #131414;
  scrollbar-width: thin;
}

body {
  color: var(--app-text);
  background: var(--app-bg);
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  letter-spacing: -0.008em;
}

::selection { color: #111212; background: #dfe0da; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: #131414; }
*::-webkit-scrollbar-thumb { background: #454745; border: 2px solid #131414; border-radius: 10px; }

.app-header {
  min-height: 78px;
  padding: 13px 24px;
  background: rgb(13 14 14 / 94%);
  color: var(--app-text);
  border-color: var(--app-line);
}

.brand-lockup { display: flex; align-items: center; gap: 16px; min-width: 220px; }
.brand-lockup img { width: 100px; height: 32px; object-fit: contain; filter: invert(1); opacity: 0.92; }
.brand-lockup > div { padding-left: 16px; border-left: 1px solid var(--app-line-strong); }
.brand-lockup h1 { margin: 0; font-size: 16px; font-weight: 560; letter-spacing: -0.025em; }
.brand-lockup p { margin: 4px 0 0; color: var(--app-faint); font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.app-kicker { display: none; }

.header-actions { gap: 9px; }
.save-status { position: relative; margin-right: 12px; padding-left: 15px; color: var(--app-muted); font-size: 11px; }
.save-status::before { content: ""; position: absolute; top: 50%; left: 0; width: 6px; height: 6px; border-radius: 50%; background: #aeb2aa; box-shadow: 0 0 0 4px rgb(174 178 170 / 8%); transform: translateY(-50%); }

.button {
  min-height: 42px;
  padding: 0 17px;
  border-radius: var(--control-radius);
  border-color: var(--app-line-strong);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.015em;
  transition: transform 180ms cubic-bezier(.16, 1, .3, 1), background-color 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.button:focus-visible, .view-switch button:focus-visible, .text-button:focus-visible, .reset-button:focus-visible, .remove-button:focus-visible { outline: 2px solid var(--app-highlight); outline-offset: 3px; }
.button:hover { background: #222323; border-color: #686a67; }
.button:active { transform: translateY(1px) scale(0.985); }
.button-secondary { color: var(--app-text); background: #151616; }
.button-primary { min-width: 116px; color: #111212; background: var(--app-highlight); border-color: var(--app-highlight); }
.button-primary:hover { color: #111212; background: #f2f2ee; border-color: #f2f2ee; }

.view-switch { display: none; }

.workspace {
  width: 100%;
  max-width: none;
  min-height: calc(100dvh - 78px);
  grid-template-columns: minmax(390px, 452px) minmax(0, 1fr);
}

.editor {
  height: calc(100dvh - 78px);
  padding: 42px 34px 84px;
  color: var(--app-text);
  background: var(--app-surface);
  border-color: var(--app-line);
}

.editor-intro { padding-bottom: 32px; border-color: var(--app-line); }
.editor-intro h2 { margin: 0; max-width: 330px; font-size: clamp(31px, 2.5vw, 40px); font-weight: 500; line-height: 1.02; letter-spacing: -0.04em; }
.editor-intro p { max-width: 34ch; margin-top: 13px; color: var(--app-muted); font-size: 13px; line-height: 1.55; }
.editor-summary { margin-top: 30px; padding-top: 17px; display: flex; align-items: baseline; justify-content: space-between; border-top: 1px solid var(--app-line); }
.editor-summary span { color: var(--app-faint); font-size: 10px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; }
.editor-summary strong { color: var(--app-text); font-size: 17px; font-weight: 540; font-variant-numeric: tabular-nums; }

.form-section { padding: 33px 0; border-color: var(--app-line); scroll-margin-top: 48px; }
.form-section h3 { margin: 0 0 22px; color: var(--app-text); font-size: 19px; font-weight: 520; letter-spacing: -0.025em; text-transform: none; }
.section-heading-row { align-items: center; }
.field-grid { gap: 17px; }

.profile-status { color: var(--app-faint); font-size: 11px; font-weight: 600; }
.profile-status.is-dirty { color: var(--app-text); }
.client-profile-manager { margin: -4px 0 24px; padding-bottom: 24px; display: grid; gap: 12px; border-bottom: 1px solid var(--app-line); }
.profile-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.profile-actions button { min-height: 34px; padding: 0 10px; }
.profile-actions .remove-button { margin-left: auto; }
.profile-actions .remove-button:disabled { color: var(--app-faint); cursor: not-allowed; opacity: 0.45; }
.profile-create { padding-top: 15px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 12px; border-top: 1px solid var(--app-line); }
.profile-create-actions { min-height: 46px; display: flex; align-items: center; gap: 12px; }
.profile-create-actions .reset-button { margin: 0; }
.profile-note { margin: 0; color: var(--app-faint); font-size: 12px; line-height: 1.45; }

label:not(.button) { gap: 8px; }
label:not(.button) > span { color: var(--app-muted); font-size: 10px; font-weight: 620; letter-spacing: 0.025em; }
.select-field, .date-field { display: grid; gap: 8px; }
.select-field > label, .date-field > label { color: var(--app-muted); font-size: 10px; font-weight: 620; letter-spacing: 0.025em; }
input, select, textarea {
  min-height: 46px;
  padding: 12px 13px;
  color: var(--app-text);
  caret-color: var(--app-text);
  background: var(--app-field);
  border-color: var(--app-line-strong);
  border-radius: var(--control-radius);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 3%);
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

input:hover, select:hover, textarea:hover { background-color: #242525; border-color: #5a5d59; }
input:focus, select:focus, textarea:focus { background-color: #242525; border-color: #b8bab4; box-shadow: 0 0 0 3px rgb(223 224 218 / 10%), inset 0 1px 0 rgb(255 255 255 / 4%); }
input:invalid { border-color: #ae6f6f; }
select {
  padding-right: 44px;
  color-scheme: dark;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5l5-5' stroke='%23c7c9c3' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 12px 8px;
}

.native-select, .native-date {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.custom-select, .custom-date { position: relative; width: 100%; }
.custom-select-trigger, .custom-date-trigger {
  width: 100%;
  min-height: 46px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--app-text);
  background: var(--app-field);
  border: 1px solid var(--app-line-strong);
  border-radius: var(--control-radius);
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 3%);
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.custom-select-trigger:hover, .custom-date-trigger:hover { background-color: #242525; border-color: #5a5d59; }
.custom-select-trigger:focus-visible, .custom-date-trigger:focus-visible { outline: 2px solid var(--app-highlight); outline-offset: 3px; }
.custom-select.is-open .custom-select-trigger, .custom-date.is-open .custom-date-trigger { background-color: #242525; border-color: #b8bab4; box-shadow: 0 0 0 3px rgb(223 224 218 / 10%), inset 0 1px 0 rgb(255 255 255 / 4%); }
.custom-select-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-select-chevron { width: 12px; height: 8px; flex: 0 0 auto; fill: none; stroke: var(--app-muted); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; transition: transform 180ms cubic-bezier(.16, 1, .3, 1); }
.custom-select.is-open .custom-select-chevron { transform: rotate(180deg); }

.custom-date-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.custom-date-icon { width: 17px; height: 17px; flex: 0 0 auto; color: var(--app-muted); fill: none; stroke: currentColor; stroke-width: 1.35; stroke-linecap: round; stroke-linejoin: round; transition: color 160ms ease, transform 180ms cubic-bezier(.16, 1, .3, 1); }
.custom-date.is-open .custom-date-icon { color: var(--app-text); transform: translateY(-1px); }

.custom-select-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  max-height: 240px;
  padding: 6px;
  overflow-y: auto;
  color: var(--app-text);
  background: var(--app-elevated);
  border-radius: var(--control-radius);
  box-shadow: 0 20px 48px rgb(0 0 0 / 42%);
  opacity: 0;
  clip-path: inset(0 0 100% 0 round 12px);
  transform: translateY(-7px) scale(0.985);
  transform-origin: top center;
  transition: opacity 120ms ease, clip-path 150ms ease, transform 150ms ease;
}

.custom-select[data-placement="top"] .custom-select-panel {
  top: auto;
  bottom: calc(100% + 8px);
  clip-path: inset(100% 0 0 0 round 12px);
  transform: translateY(7px) scale(0.985);
  transform-origin: bottom center;
}

.custom-select.is-open .custom-select-panel { opacity: 1; clip-path: inset(0 round 12px); transform: translateY(0) scale(1); transition-duration: 150ms, 180ms, 180ms; }
.custom-select-option {
  width: 100%;
  min-height: 42px;
  padding: 10px 28px 10px 12px;
  position: relative;
  display: block;
  color: var(--app-muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  transition: color 120ms ease, background-color 120ms ease;
}

.custom-select-option:hover { color: var(--app-text); background: #242525; }
.custom-select-option:focus-visible { color: var(--app-text); background: #242525; outline: 2px solid var(--app-highlight); outline-offset: -2px; }
.custom-select-option[aria-selected="true"] { color: var(--app-text); background: var(--app-field); }
.custom-select-option[aria-selected="true"]::after { content: ""; position: absolute; top: 50%; right: 13px; width: 5px; height: 5px; border-radius: 50%; background: var(--app-highlight); transform: translateY(-50%); }
.custom-select-option:disabled { color: var(--app-faint); cursor: not-allowed; opacity: 0.5; }

.custom-date-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  right: 0;
  width: 312px;
  padding: 14px;
  color: var(--app-text);
  background: var(--app-elevated);
  border-radius: var(--control-radius);
  box-shadow: 0 20px 48px rgb(0 0 0 / 42%);
  opacity: 0;
  clip-path: inset(0 0 100% 0 round 12px);
  transform: translateY(-7px) scale(0.985);
  transform-origin: top right;
  transition: opacity 120ms ease, clip-path 150ms ease, transform 150ms ease;
}

.custom-date[data-placement="top"] .custom-date-panel {
  top: auto;
  bottom: calc(100% + 8px);
  clip-path: inset(100% 0 0 0 round 12px);
  transform: translateY(7px) scale(0.985);
  transform-origin: bottom right;
}

.custom-date.is-open .custom-date-panel {
  opacity: 1;
  clip-path: inset(0 round 12px);
  transform: translateY(0) scale(1);
  transition-duration: 150ms, 180ms, 180ms;
}

.custom-date-header { min-height: 40px; margin-bottom: 9px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.custom-date-month { padding-left: 7px; font-size: 13px; font-weight: 650; letter-spacing: -0.012em; }
.custom-date-nav { display: flex; gap: 2px; }
.custom-date-nav button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--app-muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  transition: color 120ms ease, background-color 120ms ease;
}
.custom-date-nav button:hover { color: var(--app-text); background: #272828; }
.custom-date-nav button:focus-visible { outline: 2px solid var(--app-highlight); outline-offset: -2px; }
.custom-date-nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.35; stroke-linecap: round; stroke-linejoin: round; }

.custom-date-weekdays, .custom-date-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.custom-date-weekdays { margin-bottom: 4px; color: var(--app-faint); font-size: 10px; font-weight: 700; letter-spacing: 0.035em; text-align: center; text-transform: uppercase; }
.custom-date-weekdays span { min-height: 25px; display: grid; place-items: center; }
.custom-date-days { overflow: hidden; }
.custom-date-day {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--app-muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  transition: color 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}
.custom-date-day:hover { color: var(--app-text); background: #292a2a; }
.custom-date-day:focus-visible { color: var(--app-text); outline: 2px solid var(--app-highlight); outline-offset: -2px; }
.custom-date-day.is-adjacent { color: #6f716d; }
.custom-date-day.is-today { box-shadow: inset 0 0 0 1px var(--app-muted); }
.custom-date-day[aria-selected="true"] { color: #171817; background: var(--app-highlight); box-shadow: none; font-weight: 700; }

.custom-date-footer { margin-top: 10px; padding-top: 10px; display: flex; justify-content: flex-end; border-top: 1px solid var(--app-line); }
.custom-date-footer button { min-height: 34px; padding: 0 9px; color: var(--app-muted); background: transparent; border: 0; border-radius: 9px; cursor: pointer; font-size: 11px; font-weight: 650; transition: color 120ms ease, background-color 120ms ease; }
.custom-date-footer button:hover { color: var(--app-text); background: #272828; }
.custom-date-footer button:focus-visible { outline: 2px solid var(--app-highlight); outline-offset: -2px; }

.line-items { gap: 14px; }
.line-item {
  padding: 18px;
  gap: 14px;
  background: var(--app-elevated);
  border: 1px solid var(--app-line);
  border-left-width: 1px;
  border-radius: var(--control-radius);
  box-shadow: 0 16px 36px rgb(0 0 0 / 12%);
}

.text-button, .remove-button, .reset-button { color: var(--app-muted); font-size: 11px; font-weight: 650; text-underline-offset: 4px; }
.text-button { padding: 7px 10px; color: var(--app-text); border: 1px solid var(--app-line-strong); border-radius: 9px; }
.text-button:hover { text-decoration: none; background: var(--app-field); }
.remove-button { color: #d6a4a4; }
.remove-button:disabled { color: var(--app-faint); cursor: not-allowed; opacity: 0.5; }
.reset-button { margin-top: 28px; color: var(--app-faint); }

.preview-stage {
  min-width: 0;
  padding: 28px 36px 80px;
  background: #242625;
  box-shadow: inset 18px 0 38px rgb(0 0 0 / 10%);
}

.preview-toolbar {
  width: min(794px, 100%);
  min-height: 46px;
  margin: 0 auto 17px;
  display: flex;
  align-items: center;
  color: var(--app-text);
}

.preview-toolbar > div { display: grid; gap: 4px; }
.preview-toolbar > div strong { font-size: 12px; font-weight: 620; }
.preview-toolbar > div span { color: var(--app-muted); font-size: 11px; }
.preview-toolbar > strong { font-size: 12px; font-weight: 560; font-variant-numeric: tabular-nums; }
.paper-wrap { filter: drop-shadow(0 32px 52px rgb(0 0 0 / 30%)); }
.invoice-paper { box-shadow: 0 1px 0 rgb(255 255 255 / 35%); }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 10; padding: 13px 17px; color: var(--app-text); background: #202121; border: 1px solid var(--app-line-strong); border-radius: var(--control-radius); opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; font-size: 12px; }
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 400px minmax(0, 1fr); }
  .paper-wrap { margin-left: calc(50% - 309.66px); transform: scale(0.78); transform-origin: top left; }
  .preview-stage { overflow: hidden; }
}

@media (max-width: 820px) {
  .app-header { position: sticky; padding: 12px 16px 0; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; }
  .brand-lockup { min-width: 0; gap: 12px; }
  .brand-lockup img { width: 78px; }
  .brand-lockup > div { padding-left: 12px; }
  .brand-lockup h1 { font-size: 14px; }
  .brand-lockup p { font-size: 11px; }
  .save-status { display: none; }
  .header-actions { flex-wrap: nowrap; }
  .button-primary { min-width: 110px; }
  .view-switch { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; margin-top: 1px; padding-top: 8px; border-top: 1px solid var(--app-line); }
  .view-switch button { min-height: 42px; color: var(--app-faint); background: transparent; border: 0; border-bottom: 2px solid transparent; cursor: pointer; font-size: 11px; font-weight: 650; }
  .view-switch button[aria-pressed="true"] { color: var(--app-text); border-bottom-color: var(--app-highlight); }
  .workspace { display: block; }
  .editor { height: auto; min-height: calc(100dvh - 121px); padding: 36px 24px 72px; overflow: visible; border-right: 0; }
  .preview-stage { min-height: calc(100dvh - 121px); padding: 22px 0 40px; overflow: hidden; }
  .paper-wrap { margin-left: calc(50% - 269.96px); transform: scale(0.68); transform-origin: top left; }
  .preview-toolbar { padding: 0 20px; }
  body[data-mobile-view="edit"] .preview-stage { display: none; }
  body[data-mobile-view="preview"] .editor { display: none; }
}

@media (max-width: 640px) {
  .app-header { grid-template-columns: 1fr; }
  .header-actions { grid-row: 2; display: grid; grid-template-columns: 1fr 1fr 1.35fr; gap: 8px; }
  .header-actions .button { width: 100%; }
  .view-switch { grid-row: 3; }
}

@media (max-width: 520px) {
  .button { padding: 0 13px; }
  .editor { padding-inline: 16px; }
  .field-grid.two-columns { grid-template-columns: 1fr; }
  .line-item { grid-template-columns: 1fr; }
  .line-item .wide, .line-item-actions { grid-column: 1; }
  .profile-create { grid-template-columns: 1fr; align-items: stretch; }
  .profile-actions .remove-button { margin-left: 0; }
  .paper-wrap { margin-left: calc(50% - 192.55px); transform: scale(0.485); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}

@page { size: A4; margin: 0; }

@media print {
  html, body { width: 595pt; height: 842pt; background: #fff; }
  .app-header, .editor, .preview-toolbar, .toast, .view-switch { display: none !important; }
  .workspace, .preview-stage, .paper-wrap { display: block !important; width: 595pt; height: 842pt; margin: 0; padding: 0; overflow: visible; transform: none; translate: none; }
  .invoice-paper { width: 595pt; min-height: 842pt; height: 842pt; margin: 0; box-shadow: none; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
