:root {
  --ink: #19202a;
  --ink-soft: #3e4a59;
  --paper: #fbfaf6;
  --panel: #ffffff;
  --line: #d9d5c9;
  --line-strong: #b9b09d;
  --brass: #b58b2b;
  --emerald: #1f7a63;
  --garnet: #9b2f45;
  --sky: #426f96;
  --mist: #f2f0e8;
  --shadow: 0 16px 40px rgba(25, 32, 42, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

body.theme-light {
  --ink: #17202c;
  --ink-soft: #4b5563;
  --paper: #f7f8fb;
  --panel: #ffffff;
  --line: #d7dce5;
  --line-strong: #aeb8c8;
  --mist: #eef1f6;
  --shadow: 0 14px 34px rgba(23, 32, 44, .08);
  --sidebar-bg: #17202c;
}

body.theme-dark {
  --ink: #edf2f7;
  --ink-soft: #b8c3cf;
  --paper: #111827;
  --panel: #1f2937;
  --line: #374151;
  --line-strong: #4b5563;
  --brass: #d7b65f;
  --garnet: #f08aa0;
  --sky: #8ec5f4;
  --mist: #273244;
  --shadow: 0 16px 40px rgba(0, 0, 0, .22);
  --sidebar-bg: #0b1220;
}

body.theme-contrast {
  --ink: #000000;
  --ink-soft: #1f2937;
  --paper: #ffffff;
  --panel: #ffffff;
  --line: #000000;
  --line-strong: #000000;
  --brass: #7a4d00;
  --garnet: #8b0025;
  --sky: #003c78;
  --mist: #f1f1f1;
  --shadow: none;
  --sidebar-bg: #000000;
}

body.font-small {
  font-size: 14px;
}

body.font-large {
  font-size: 17px;
}

body.density-compact .main {
  padding: 16px;
}

body.density-compact .panel {
  padding: 12px;
  margin-bottom: 12px;
}

body.density-compact th,
body.density-compact td {
  padding: 7px 8px;
}

body.nav-compact .app-shell {
  grid-template-columns: 192px minmax(0, 1fr);
}

body.nav-compact .sidebar {
  padding: 18px 12px;
}

body.nav-compact .sidebar nav a {
  padding: 8px 9px;
  font-size: 13px;
}

body.cards-flat {
  --shadow: none;
}

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.summary-strip span {
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--mist);
  border-radius: 6px;
}

.mfa-secret {
  display: block;
  padding: 12px;
  margin: 12px 0;
  border: 1px dashed var(--line-strong);
  background: var(--mist);
  color: var(--ink);
  font-size: 16px;
  overflow-wrap: anywhere;
}

.recovery-codes {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.recovery-codes code {
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--mist);
  color: var(--ink);
  text-align: center;
}

body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  transition: none !important;
  animation: none !important;
  scroll-behavior: auto !important;
}

a {
  color: var(--emerald);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
a,
input,
select,
textarea {
  touch-action: manipulation;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}

.sidebar {
  background: var(--sidebar-bg, var(--ink));
  color: white;
  padding: 22px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-backdrop,
.mobile-menu-toggle {
  display: none;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: white;
  margin-bottom: 28px;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  background: var(--brass);
  color: var(--ink);
  font-weight: 800;
  border-radius: 8px;
}

.brand small,
.user-chip small {
  display: block;
  color: rgba(255, 255, 255, .68);
  font-size: 12px;
  margin-top: 2px;
}

.sidebar nav {
  display: grid;
  gap: 4px;
}

.sidebar nav a {
  color: rgba(255, 255, 255, .74);
  padding: 10px 12px;
  border-radius: 8px;
}

.sidebar nav a.active,
.sidebar nav a:hover {
  background: rgba(255, 255, 255, .1);
  color: white;
  text-decoration: none;
}

.main {
  padding: 24px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h1,
.panel h2,
.install-panel h1,
.login-card h1 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--brass);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
}

.top-actions,
.button-row,
.switch-row,
.filter-bar,
.inline-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-chip {
  background: var(--sidebar-bg, var(--ink));
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  line-height: 1.2;
}

.button,
button.button {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  min-height: 38px;
  padding: 8px 13px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  cursor: pointer;
}

.button:hover {
  text-decoration: none;
  border-color: var(--ink);
}

.button:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid rgba(31, 122, 99, .28);
  outline-offset: 2px;
}

.button.primary {
  background: var(--emerald);
  color: white;
  border-color: var(--emerald);
}

.button.ghost {
  background: transparent;
}

.button.danger {
  border-color: var(--garnet);
  color: var(--garnet);
}

.button.large {
  width: 100%;
  min-height: 46px;
  font-weight: 700;
}

.button.small {
  min-height: 34px;
  padding: 4px 9px;
}

.icon-button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

body.theme-dark .button,
body.theme-dark button.button,
body.theme-dark .icon-button,
body.theme-dark .mobile-menu-toggle,
body.theme-dark .quick-grid a,
body.theme-dark .tabs a,
body.theme-dark .assistant-command-list button,
body.theme-dark .assistant-suggestions button {
  background-color: var(--panel);
  color: var(--ink);
  border-color: var(--line-strong);
}

body.theme-dark .button:hover,
body.theme-dark .button:focus,
body.theme-dark .button:active,
body.theme-dark button.button:hover,
body.theme-dark button.button:focus,
body.theme-dark button.button:active,
body.theme-dark .icon-button:hover,
body.theme-dark .icon-button:focus,
body.theme-dark .icon-button:active,
body.theme-dark .mobile-menu-toggle:hover,
body.theme-dark .mobile-menu-toggle:focus,
body.theme-dark .mobile-menu-toggle:active,
body.theme-dark .quick-grid a:hover,
body.theme-dark .quick-grid a:focus,
body.theme-dark .quick-grid a:active,
body.theme-dark .tabs a:hover,
body.theme-dark .tabs a:focus,
body.theme-dark .tabs a:active,
body.theme-dark .assistant-command-list button:hover,
body.theme-dark .assistant-command-list button:focus,
body.theme-dark .assistant-command-list button:active,
body.theme-dark .assistant-suggestions button:hover,
body.theme-dark .assistant-suggestions button:focus,
body.theme-dark .assistant-suggestions button:active {
  background-color: var(--mist);
  color: var(--ink);
  border-color: var(--emerald);
}

body.theme-dark .button.primary,
body.theme-dark button.button.primary {
  background-color: var(--emerald);
  color: #fff;
  border-color: var(--emerald);
}

body.theme-dark .button.primary:hover,
body.theme-dark .button.primary:focus,
body.theme-dark .button.primary:active,
body.theme-dark button.button.primary:hover,
body.theme-dark button.button.primary:focus,
body.theme-dark button.button.primary:active {
  background-color: #249477;
  color: #fff;
  border-color: #249477;
}

body.theme-dark .button.ghost {
  background-color: transparent;
  color: var(--ink);
}

body.theme-dark .button.ghost:hover,
body.theme-dark .button.ghost:focus,
body.theme-dark .button.ghost:active {
  background-color: var(--mist);
  color: var(--ink);
}

body.theme-dark .button.danger {
  background-color: transparent;
  border-color: var(--garnet);
  color: var(--garnet);
}

body.theme-dark .button.danger:hover,
body.theme-dark .button.danger:focus,
body.theme-dark .button.danger:active {
  background-color: rgba(155, 47, 69, .18);
  border-color: var(--garnet);
  color: var(--garnet);
}

.panel,
.kpi,
.invoice-sheet,
.login-card,
.install-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
  margin-bottom: 18px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 18px;
}

.panel h3 {
  margin: 16px 0 8px;
  font-size: 15px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-grid.mini {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.kpi {
  padding: 16px;
  box-shadow: none;
}

.kpi span {
  display: block;
  color: var(--ink-soft);
  font-size: 13px;
  margin-bottom: 8px;
}

.kpi strong {
  font-size: 22px;
}

.kpi.accent {
  border-color: rgba(31, 122, 99, .35);
  background: var(--accent-soft, #eef8f3);
}

body.theme-dark .kpi.accent {
  border-color: rgba(142, 197, 244, .28);
  background: rgba(31, 122, 99, .16);
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.split-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.side-form {
  position: sticky;
  top: 18px;
}

.stacked-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-soft);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  min-height: 38px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--ink-soft);
  opacity: .78;
}

option,
optgroup {
  background: var(--panel);
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(31, 122, 99, .22);
  border-color: var(--emerald);
}

body.theme-dark input,
body.theme-dark select,
body.theme-dark textarea,
body.theme-dark input[type="date"],
body.theme-dark input[type="month"],
body.theme-dark input[type="time"],
body.theme-dark input[type="datetime-local"],
body.theme-dark input[type="number"],
body.theme-dark input[type="email"],
body.theme-dark input[type="password"],
body.theme-dark input[type="search"],
body.theme-dark input[type="file"],
body.theme-contrast input,
body.theme-contrast select,
body.theme-contrast textarea {
  background-color: var(--panel) !important;
  color: var(--ink) !important;
  border-color: var(--line);
  color-scheme: dark;
}

body.theme-dark option,
body.theme-dark optgroup,
body.theme-contrast option,
body.theme-contrast optgroup {
  background-color: var(--panel);
  color: var(--ink);
}

body.theme-dark input:-webkit-autofill,
body.theme-dark input:-webkit-autofill:hover,
body.theme-dark input:-webkit-autofill:focus,
body.theme-dark textarea:-webkit-autofill,
body.theme-dark select:-webkit-autofill {
  -webkit-text-fill-color: var(--ink) !important;
  box-shadow: 0 0 0 1000px var(--panel) inset !important;
  caret-color: var(--ink);
}

body.theme-dark input:disabled,
body.theme-dark select:disabled,
body.theme-dark textarea:disabled {
  background-color: var(--mist) !important;
  color: var(--ink-soft) !important;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: var(--mist);
  color: var(--ink-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

tr:last-child td {
  border-bottom: 0;
}

.compact th,
.compact td,
.line-table th,
.line-table td {
  padding: 7px;
}

.line-table input,
.line-table select,
.journal-form input,
.journal-form select {
  min-width: 90px;
  padding: 7px;
}

.line-table [data-line-description] {
  min-width: 220px;
}

.line-table::before {
  display: none;
}

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 24px;
}

.total-row td {
  font-weight: 800;
  background: var(--mist);
}

.total-row.grand td {
  color: var(--emerald);
}

.notice {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  margin-bottom: 14px;
  background: var(--panel);
}

.notice.success {
  border-color: rgba(31, 122, 99, .35);
  background: var(--accent-soft, #eef8f3);
}

.notice.danger {
  border-color: rgba(155, 47, 69, .35);
  background: #fff2f4;
}

body.theme-dark .notice.success {
  border-color: rgba(31, 122, 99, .42);
  background: rgba(31, 122, 99, .18);
  color: var(--ink);
}

body.theme-dark .notice.danger {
  border-color: rgba(240, 138, 160, .42);
  background: rgba(155, 47, 69, .18);
  color: var(--ink);
}

.muted {
  color: var(--ink-soft);
}

.small {
  font-size: 13px;
}

.pill,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--mist);
  color: var(--ink-soft);
  text-transform: capitalize;
}

.pill.warn {
  background: #fff5db;
  color: #8a6200;
}

body.theme-dark .pill.warn {
  background: rgba(181, 139, 43, .18);
  color: var(--brass);
}

.status.posted,
.status.paid,
.status.matched,
.status.verified,
.status.approved,
.status.generated,
.status.success {
  background: #e9f7f1;
  color: var(--emerald);
}

body.theme-dark .status.posted,
body.theme-dark .status.paid,
body.theme-dark .status.matched,
body.theme-dark .status.verified,
body.theme-dark .status.approved,
body.theme-dark .status.generated,
body.theme-dark .status.success {
  background: rgba(31, 122, 99, .18);
  color: #9ee7ce;
}

.status.part_paid,
.status.suggested,
.status.open,
.status.customer_paid,
.status.pending,
.status.needs_review,
.status.difference {
  background: #edf4fb;
  color: var(--sky);
}

body.theme-dark .status.part_paid,
body.theme-dark .status.suggested,
body.theme-dark .status.open,
body.theme-dark .status.customer_paid,
body.theme-dark .status.pending,
body.theme-dark .status.needs_review,
body.theme-dark .status.difference {
  background: rgba(66, 111, 150, .22);
  color: var(--sky);
}

.status.void,
.status.unmatched,
.status.draft,
.status.cancelled,
.status.expired,
.status.failed,
.status.rejected,
.status.missing_in_books {
  background: #fff2f4;
  color: var(--garnet);
}

body.theme-dark .status.void,
body.theme-dark .status.unmatched,
body.theme-dark .status.draft,
body.theme-dark .status.cancelled,
body.theme-dark .status.expired,
body.theme-dark .status.failed,
body.theme-dark .status.rejected,
body.theme-dark .status.missing_in_books {
  background: rgba(155, 47, 69, .2);
  color: var(--garnet);
}

.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;
}

.assistant-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.assistant-chat {
  min-height: calc(100vh - 120px);
  display: grid;
  grid-template-rows: auto minmax(340px, 1fr) auto;
  gap: 14px;
}

.assistant-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 4px;
  max-height: calc(100vh - 270px);
}

.assistant-message {
  display: flex;
}

.assistant-message.user {
  justify-content: flex-end;
}

.assistant-bubble {
  max-width: min(760px, 92%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  background: var(--mist);
  color: var(--ink);
}

.assistant-message.user .assistant-bubble {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #fff;
}

.assistant-bubble p {
  margin: 0;
}

.assistant-result {
  margin-top: 10px;
}

.assistant-result .table-wrap {
  margin-top: 8px;
  background: var(--panel);
}

.assistant-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.assistant-kpis div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: var(--panel);
}

.assistant-kpis span {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.assistant-kpis strong {
  font-size: 15px;
  color: var(--ink);
}

.assistant-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.assistant-compose textarea {
  min-height: 54px;
  max-height: 140px;
}

.assistant-compose.is-busy textarea {
  opacity: .72;
}

.assistant-guide {
  position: sticky;
  top: 18px;
}

.assistant-command-list,
.assistant-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.assistant-command-list {
  margin: 10px 0 16px;
}

.assistant-command-list button,
.assistant-suggestions button,
.text-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--emerald);
  padding: 7px 9px;
  font: inherit;
  cursor: pointer;
}

.assistant-suggestions {
  margin-top: 10px;
}

.assistant-suggestions button {
  font-size: 12px;
  min-height: 30px;
}

.text-button {
  display: inline;
  padding: 0;
  min-height: 0;
  border: 0;
  background: transparent;
  text-decoration: underline;
}

.assistant-example {
  margin: 8px 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--mist);
  color: var(--ink);
  font-size: 13px;
}

.biz-floating-chat {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
}

.biz-fab {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .28);
  background: var(--emerald);
  color: #fff;
  box-shadow: 0 16px 34px rgba(25, 32, 42, .22);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.biz-fab span {
  display: inline-grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.biz-chat-window {
  position: absolute;
  right: 0;
  bottom: 78px;
  width: min(390px, calc(100vw - 28px));
  max-height: min(640px, calc(100vh - 118px));
  display: grid;
  grid-template-rows: auto minmax(220px, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 22px 60px rgba(25, 32, 42, .24);
}

.biz-chat-window[hidden] {
  display: none;
}

.biz-chat-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.biz-chat-head strong {
  display: block;
  font-size: 20px;
}

.biz-chat-messages {
  max-height: none;
  padding-right: 2px;
}

.biz-chat-messages .assistant-bubble {
  max-width: 100%;
}

.biz-chat-compose {
  grid-template-columns: 1fr;
}

.biz-chat-compose .button {
  width: 100%;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.quick-grid a {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  color: var(--ink);
  background: var(--panel);
}

.quick-grid a:hover {
  border-color: var(--emerald);
  text-decoration: none;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}

.totals-list {
  margin: 0;
  display: grid;
  gap: 8px;
}

.totals-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.totals-list dt,
.totals-list dd {
  margin: 0;
}

.totals-list dd {
  font-weight: 700;
}

.totals-list .grand {
  color: var(--emerald);
  font-size: 18px;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tabs a {
  color: var(--ink-soft);
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 12px;
}

.tabs a.active {
  color: white;
  background: var(--ink);
  border-color: var(--ink);
}

.accordion-panel summary {
  display: grid;
  gap: 4px;
  cursor: pointer;
  padding: 4px 0;
  font-weight: 700;
}

.accordion-panel summary small {
  color: var(--ink-soft);
  font-weight: 400;
}

.accordion-panel .accordion-body {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.settings-reset-form {
  margin-top: 12px;
}

.switch-line {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}

.switch-line input {
  width: auto;
  min-height: auto;
}

.appearance-preview {
  align-self: start;
}

.preview-shell {
  display: grid;
  grid-template-columns: 145px minmax(0, 1fr);
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper);
}

.preview-shell aside {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 14px;
  color: white;
  background: var(--sidebar-bg, var(--ink));
}

.preview-shell aside strong {
  margin-bottom: 8px;
}

.preview-shell aside span {
  min-height: 30px;
  display: flex;
  align-items: center;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .1);
}

.preview-shell main {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 16px;
  background: var(--paper);
}

.preview-shell h3 {
  margin: 0;
  letter-spacing: 0;
}

.preview-kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.preview-kpis div {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.preview-kpis span {
  color: var(--ink-soft);
  font-size: 12px;
}

.filter-bar {
  margin-bottom: 14px;
}

.filter-bar label {
  min-width: 170px;
}

.invoice-sheet {
  padding: 28px;
  max-width: 1060px;
  margin: 0 auto 22px;
}

.barcode-scan-strip {
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(0, 1fr);
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.success-text {
  color: var(--emerald);
}

.danger-text {
  color: var(--garnet);
}

.barcode-label-sheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.barcode-label {
  min-height: 160px;
  padding: 12px;
  border: 1px dashed var(--ink);
  background: var(--panel);
  display: grid;
  gap: 5px;
  page-break-inside: avoid;
}

.barcode-company,
.barcode-meta {
  color: var(--ink-soft);
  font-size: 11px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.barcode-symbol {
  display: flex;
  align-items: stretch;
  height: 46px;
  margin: 6px 0 2px;
  background: white;
}

.barcode-symbol .bar {
  background: #000;
  height: 46px;
}

.barcode-symbol .space {
  background: #fff;
  height: 46px;
}

.barcode-symbol .narrow {
  width: 2px;
}

.barcode-symbol .wide {
  width: 5px;
}

.invoice-head,
.invoice-parties,
.invoice-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}

.invoice-company,
.invoice-parties div {
  display: grid;
  gap: 5px;
}

.invoice-parties {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 20px 0;
  padding: 16px 0;
}

.invoice-bottom {
  margin-top: 18px;
}

.qr-block {
  display: inline-grid;
  gap: 6px;
  margin: 12px 16px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  vertical-align: top;
}

.qr-block p {
  margin: 0;
}

.qr-block img {
  width: 160px;
  height: 160px;
  object-fit: contain;
}

.print-total {
  max-width: 340px;
  justify-self: end;
  width: 100%;
}

.payment-body {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(31, 122, 99, .11), transparent 42%),
    linear-gradient(315deg, rgba(181, 139, 43, .16), transparent 46%),
    var(--paper);
}

.payment-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 18px;
  display: grid;
  place-items: center;
}

.payment-card {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.payment-card h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.payment-hero,
.payment-grid,
.payment-footer {
  display: grid;
  gap: 18px;
}

.payment-hero {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  margin-bottom: 18px;
}

.payment-grid {
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: start;
}

.payment-qr {
  display: grid;
  gap: 12px;
  justify-items: center;
  text-align: center;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.payment-qr img {
  width: 220px;
  max-width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
}

.payment-reference-form {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.payment-footer {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
  color: var(--ink-soft);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.login-body,
.install-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(31, 122, 99, .12), transparent 42%),
    linear-gradient(315deg, rgba(181, 139, 43, .16), transparent 44%),
    var(--paper);
}

.login-card,
.install-panel {
  width: min(100%, 460px);
  padding: 28px;
}

.register-card {
  width: min(100%, 920px);
}

.register-card h2 {
  margin-top: 10px;
  font-size: 16px;
}

.auth-link {
  text-align: center;
}

.register-options {
  display: grid;
  gap: 10px;
}

.register-options label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.register-options input {
  width: auto;
  min-height: auto;
}

.install-shell {
  width: min(100%, 1080px);
}

.install-panel {
  width: 100%;
}

.install-panel h2 {
  margin: 18px 0 4px;
}

.document-actions form {
  display: inline;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .sidebar nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .kpi-grid,
  .kpi-grid.mini,
  .grid.four,
  .grid.two,
  .split-view,
  .assistant-shell,
  .invoice-head,
  .invoice-parties,
  .invoice-bottom,
  .permission-grid {
    grid-template-columns: 1fr;
  }

  .side-form {
    position: static;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 14px;
  }

  body.nav-open {
    overflow: hidden;
  }

  body.nav-open .biz-floating-chat {
    display: none;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 40;
    top: 0;
    left: 0;
    width: min(86vw, 320px);
    height: 100vh;
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform .22s ease;
    padding: 18px;
    box-shadow: 18px 0 48px rgba(25, 32, 42, .26);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    z-index: 35;
    inset: 0;
    background: rgba(25, 32, 42, .42);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }

  body.nav-open .sidebar-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .brand {
    margin-bottom: 16px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .sidebar nav {
    grid-template-columns: 1fr;
  }

  .sidebar nav a {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 11px 12px;
  }

  .main {
    padding: 12px;
  }

  .topbar {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    gap: 10px 12px;
    position: sticky;
    top: 0;
    z-index: 25;
    background: rgba(251, 250, 246, .94);
    backdrop-filter: blur(10px);
    margin: -12px -12px 14px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }

  body.theme-dark .topbar {
    background: rgba(17, 24, 39, .94);
  }

  .mobile-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background: var(--panel);
    color: var(--ink);
    font: inherit;
    font-weight: 700;
  }

  .topbar h1 {
    font-size: 22px;
    line-height: 1.18;
  }

  .eyebrow {
    font-size: 11px;
    overflow-wrap: anywhere;
  }

  .top-actions {
    grid-column: 1 / -1;
  }

  .top-actions,
  .button-row,
  .switch-row {
    align-items: stretch;
  }

  .top-actions > *,
  .button-row > * {
    width: 100%;
  }

  .button,
  button.button,
  input,
  select {
    min-height: 44px;
  }

  .icon-button {
    width: 42px;
    height: 42px;
  }

  .panel,
  .kpi,
  .invoice-sheet,
  .login-card,
  .install-panel {
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(25, 32, 42, .06);
  }

  .panel {
    padding: 14px;
    margin-bottom: 12px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .panel-head .button,
  .panel-head .button-row {
    width: 100%;
  }

  .assistant-chat {
    min-height: calc(100vh - 190px);
    grid-template-rows: auto minmax(300px, 1fr) auto;
  }

  .assistant-messages {
    max-height: calc(100vh - 330px);
  }

  .assistant-bubble {
    max-width: 100%;
  }

  .assistant-compose {
    grid-template-columns: 1fr;
  }

  .assistant-compose .button {
    width: 100%;
  }

  .assistant-guide {
    position: static;
  }

  .biz-floating-chat {
    right: 12px;
    bottom: 12px;
  }

  .biz-fab {
    width: 56px;
    height: 56px;
  }

  .biz-chat-window {
    position: fixed;
    inset: auto 10px 78px 10px;
    width: auto;
    max-height: min(660px, calc(100vh - 108px));
  }

  .kpi-grid,
  .kpi-grid.mini {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .kpi {
    padding: 12px;
  }

  .kpi span {
    font-size: 12px;
  }

  .kpi strong {
    font-size: 18px;
    overflow-wrap: anywhere;
  }

  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    margin: 0 -12px 14px;
    padding-left: 12px;
    scrollbar-width: thin;
  }

  .tabs a {
    white-space: nowrap;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }

  .filter-bar {
    display: grid;
    align-items: stretch;
  }

  .filter-bar label,
  .filter-bar .button {
    min-width: 0;
    width: 100%;
  }

  .barcode-scan-strip {
    grid-template-columns: 1fr;
  }

  .table-wrap:not(.line-table) {
    border: 0;
    overflow: visible;
  }

  .table-wrap:not(.line-table) table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 10px;
  }

  .table-wrap:not(.line-table) thead {
    display: none;
  }

  .table-wrap:not(.line-table) tbody,
  .table-wrap:not(.line-table) tr,
  .table-wrap:not(.line-table) td {
    display: block;
    width: 100%;
  }

  .table-wrap:not(.line-table) tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    overflow: hidden;
  }

  .table-wrap:not(.line-table) td {
    min-height: 40px;
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: minmax(96px, 38%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 10px 12px;
    overflow-wrap: anywhere;
  }

  .table-wrap:not(.line-table) td:last-child {
    border-bottom: 0;
  }

  .table-wrap:not(.line-table) td::before {
    content: attr(data-label);
    color: var(--ink-soft);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
  }

  .table-wrap:not(.line-table) td.empty {
    display: block;
    text-align: center;
  }

  .table-wrap:not(.line-table) td.empty::before {
    content: "";
  }

  .line-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .line-table::before {
    content: "Swipe sideways to edit all line item fields";
    display: block;
    position: sticky;
    left: 0;
    padding: 8px 10px;
    color: var(--ink-soft);
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    font-size: 12px;
  }

  .line-table table {
    min-width: 940px;
  }

  .line-table input,
  .line-table select,
  .journal-form input,
  .journal-form select {
    min-height: 40px;
  }

  .quick-grid {
    grid-template-columns: 1fr;
  }

  .totals-panel {
    position: sticky;
    bottom: 0;
    z-index: 15;
    box-shadow: 0 -10px 26px rgba(25, 32, 42, .08);
  }

  .invoice-sheet {
    padding: 16px;
  }

  .invoice-company,
  .invoice-parties div {
    overflow-wrap: anywhere;
  }

  .qr-block {
    width: 100%;
    margin-right: 0;
    justify-items: center;
  }

  .payment-shell {
    padding: 12px;
    place-items: start center;
  }

  .payment-card {
    padding: 16px;
  }

  .payment-card h1 {
    font-size: 22px;
    line-height: 1.18;
  }

  .payment-hero,
  .payment-grid,
  .payment-footer {
    grid-template-columns: 1fr;
  }

  .payment-qr {
    padding: 14px;
  }

  .inline-form {
    display: grid;
    width: 100%;
  }

  .install-body,
  .login-body {
    padding: 12px;
    place-items: start center;
  }

  .login-card,
  .install-panel {
    padding: 18px;
  }
}

@media (max-width: 420px) {
  .kpi-grid,
  .kpi-grid.mini {
    grid-template-columns: 1fr;
  }

  .recovery-codes {
    grid-template-columns: 1fr 1fr;
  }
}

@media print {
  body {
    background: white;
  }

  .sidebar,
  .topbar,
  .biz-floating-chat,
  .notice,
  .no-print,
  .document-actions {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .main {
    padding: 0;
  }

  .invoice-sheet {
    border: 0;
    box-shadow: none;
    padding: 0;
    max-width: none;
  }

  .barcode-label-sheet {
    display: grid;
    grid-template-columns: repeat(2, 88mm);
    gap: 5mm;
  }

  .barcode-label {
    width: 88mm;
    min-height: 52mm;
    box-shadow: none;
  }
}
