:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #eef1f4;
  --ink: #29292d;
  --muted: #68707c;
  --line: #d8dde5;
  --line-strong: #aeb7c5;
  --blue: #075fa8;
  --blue-dark: #034a83;
  --olive: #798c43;
  --charcoal: #2f3f47;
  --danger: #b42318;
  --success: #18794e;
  --warning: #a15c07;
  --nav: #17242b;
  --nav-muted: #9cacb5;
  --shadow: 0 20px 60px rgba(31, 41, 55, 0.12);
  --radius: 8px;
  --font: Avenir, Montserrat, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
}

.app-navigation {
  position: sticky;
  top: 0;
  width: 224px;
  height: 100vh;
  flex: 0 0 224px;
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  background: var(--nav);
  color: #ffffff;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 8px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.nav-logo {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  border: 2px solid #ffffff;
  border-radius: 50%;
  font-size: 23px;
  font-weight: 900;
}

.nav-brand strong,
.nav-brand span {
  display: block;
}

.nav-brand strong {
  font-size: 14px;
}

.nav-brand span {
  margin-top: 2px;
  color: var(--nav-muted);
  font-size: 12px;
}

.nav-links {
  display: grid;
  gap: 6px;
  margin-top: 20px;
}

.nav-link {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--nav-muted);
  font-size: 14px;
  font-weight: 800;
  text-align: left;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
}

.nav-link.is-active {
  background: var(--blue);
  color: #ffffff;
}

.nav-symbol {
  width: 22px;
  text-align: center;
  font-size: 20px;
  line-height: 1;
}

.nav-footer {
  display: grid;
  gap: 3px;
  margin-top: auto;
  padding: 16px 10px 2px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.nav-footer span {
  color: var(--nav-muted);
  font-size: 11px;
}

.nav-footer strong {
  font-size: 13px;
}

.app-main {
  width: calc(100% - 224px);
  min-width: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.is-hidden {
  display: none !important;
}

.topbar h1,
.panel-heading h2,
.form-section h3 {
  margin: 0;
}

.topbar h1 {
  font-size: 24px;
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions,
.preview-actions,
.section-title-row,
.panel-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button,
.icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 800;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  white-space: nowrap;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button:disabled:hover {
  transform: none;
}

.button-primary {
  background: var(--blue);
  color: #ffffff;
}

.button-dark {
  background: var(--ink);
  color: #ffffff;
}

.button-dark:hover {
  background: #11181d;
}

.button-primary:hover {
  background: var(--blue-dark);
}

.button-secondary {
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--ink);
}

.button-secondary:hover {
  background: var(--surface-muted);
}

.button-danger {
  background: #fff4f2;
  border-color: #f4b5ae;
  color: var(--danger);
}

.button-danger:hover {
  background: #ffe7e3;
}

.icon-button {
  width: 40px;
  display: inline-grid;
  place-items: center;
  background: var(--ink);
  color: #ffffff;
  font-size: 24px;
  line-height: 1;
}

.file-button {
  cursor: pointer;
}

#importFile {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.dashboard-view {
  width: 100%;
  max-width: 1500px;
  display: grid;
  gap: 16px;
  margin: 0 auto;
  padding: 20px;
}

.dashboard-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 4px 0 2px;
}

.dashboard-intro h2 {
  margin: 0;
  font-size: 25px;
}

.dashboard-intro p:last-child {
  margin: 7px 0 0;
  color: var(--muted);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 12px;
}

.kpi-card,
.dashboard-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(24, 32, 43, 0.03);
}

.kpi-card {
  min-height: 138px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 17px;
}

.kpi-card.kpi-primary {
  border-top: 3px solid var(--blue);
  padding-top: 15px;
}

.kpi-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.kpi-mark {
  min-width: 32px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: #e6f2ff;
  color: var(--blue);
  font-size: 10px;
}

.kpi-mark.success {
  background: #e5f7ee;
  color: var(--success);
}

.kpi-mark.warning {
  background: #fff1df;
  color: var(--warning);
}

.kpi-mark.danger {
  background: #fff0ee;
  color: var(--danger);
}

.kpi-card > strong {
  margin-top: 14px;
  font-size: clamp(20px, 2vw, 29px);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.kpi-card small {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.dashboard-row {
  display: grid;
  gap: 12px;
}

.dashboard-insights {
  grid-template-columns: minmax(0, 1.65fr) minmax(290px, 0.75fr);
}

.dashboard-details {
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.7fr);
}

.dashboard-panel {
  min-width: 0;
  padding: 18px;
}

.dashboard-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.dashboard-panel-heading h3 {
  margin: 0;
  font-size: 17px;
}

.panel-caption {
  color: var(--muted);
  font-size: 12px;
}

.bar-chart {
  height: 220px;
  display: grid;
  grid-template-columns: repeat(6, minmax(36px, 1fr));
  gap: 12px;
  align-items: end;
  padding-top: 18px;
  border-bottom: 1px solid var(--line);
}

.bar-column {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 10px;
  align-items: end;
}

.bar-track {
  height: 100%;
  display: flex;
  align-items: end;
  justify-content: center;
}

.bar-fill {
  position: relative;
  width: min(48px, 72%);
  min-height: 6px;
  border-radius: 4px 4px 0 0;
  background: var(--blue);
  transition: height 180ms ease;
}

.bar-fill.is-current {
  background: var(--olive);
}

.bar-fill:hover::before {
  content: attr(data-value);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  z-index: 2;
  transform: translateX(-50%);
  padding: 5px 7px;
  border-radius: 4px;
  background: var(--ink);
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.bar-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.status-overview {
  min-height: 220px;
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 20px;
  align-items: center;
}

.status-donut {
  width: 138px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--blue) 0 25%, var(--success) 25% 50%, var(--warning) 50% 75%, #aeb7c5 75% 100%);
}

.status-donut > div {
  width: 88px;
  aspect-ratio: 1;
  display: grid;
  place-content: center;
  border-radius: 50%;
  background: #ffffff;
  text-align: center;
}

.status-donut strong,
.status-donut span {
  display: block;
}

.status-donut strong {
  font-size: 26px;
}

.status-donut span {
  color: var(--muted);
  font-size: 11px;
}

.status-breakdown {
  display: grid;
  gap: 12px;
}

.status-breakdown-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.status-color {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.status-color.draft { background: #aeb7c5; }
.status-color.sent { background: var(--blue); }
.status-color.paid { background: var(--success); }
.status-color.late { background: var(--warning); }

.status-breakdown-row span:nth-child(2) {
  color: var(--muted);
}

.recent-table-wrap {
  overflow-x: auto;
}

.recent-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.recent-table th,
.recent-table td {
  padding: 11px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  text-align: left;
  overflow-wrap: anywhere;
}

.recent-table th {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

.recent-table th:nth-child(1) { width: 18%; }
.recent-table th:nth-child(2) { width: 22%; }
.recent-table th:nth-child(3) { width: 18%; }
.recent-table th:nth-child(4) { width: 17%; }
.recent-table th:nth-child(5) { width: 20%; }
.recent-table th:nth-child(6) { width: 5%; }

.recent-table td:nth-child(5),
.recent-table th:nth-child(5) {
  text-align: right;
}

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

.open-invoice {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--blue);
  font-weight: 900;
}

.open-invoice:hover {
  background: #eef6ff;
}

.text-button {
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
}

.followup-list {
  display: grid;
  gap: 8px;
}

.followup-item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  text-align: left;
}

.followup-item:hover {
  border-color: var(--blue);
}

.followup-item strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.followup-item .status-pill {
  grid-row: 1 / 3;
  grid-column: 2;
  align-self: center;
}

.followup-item small {
  color: var(--muted);
  font-size: 11px;
}

.dashboard-empty {
  padding: 24px 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

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

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(210px, 240px) minmax(640px, 1.35fr) minmax(380px, 500px);
  gap: 16px;
  padding: 16px;
}

.workspace.is-list-collapsed {
  grid-template-columns: 52px minmax(700px, 1.45fr) minmax(400px, 520px);
}

.invoice-sidebar,
.editor-panel,
.preview-panel {
  min-width: 0;
}

.invoice-sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.invoice-sidebar-heading {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.invoice-sidebar-heading strong {
  font-size: 14px;
}

.invoice-sidebar-heading button {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.invoice-sidebar-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.workspace.is-list-collapsed .invoice-sidebar-heading {
  justify-content: center;
  padding: 6px;
}

.workspace.is-list-collapsed .invoice-sidebar-heading strong,
.workspace.is-list-collapsed .invoice-sidebar-content {
  display: none;
}

.summary-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.summary-strip > div,
.toolbar,
.editor-panel,
.preview-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(24, 32, 43, 0.03);
}

.summary-strip > div {
  padding: 12px;
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-strip strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
}

.toolbar {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(7, 95, 168, 0.16);
}

.compact-field input,
.compact-field select {
  min-height: 38px;
}

.invoice-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  max-height: calc(100vh - 270px);
  padding-right: 2px;
}

.invoice-card {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  color: inherit;
}

.invoice-card.is-active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(7, 95, 168, 0.14);
}

.invoice-card header,
.invoice-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.invoice-card h3 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.invoice-card p {
  margin: 6px 0 10px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status-draft {
  background: #eef1f5;
  color: #485465;
}

.status-sent {
  background: #e6f2ff;
  color: #0d5d9f;
}

.status-paid {
  background: #e5f7ee;
  color: var(--success);
}

.status-late {
  background: #fff1df;
  color: var(--warning);
}

.editor-panel {
  overflow: hidden;
}

.editor-empty {
  min-height: 440px;
  padding: 48px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
}

.editor-empty-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: #e7eff5;
  color: var(--blue);
  font-size: 28px;
}

.editor-empty h3,
.editor-empty p {
  margin: 0;
}

.editor-empty h3 {
  font-size: 20px;
}

.editor-empty p {
  max-width: 300px;
  color: var(--muted);
}

.editor-empty .button {
  margin-top: 12px;
}

.panel-heading {
  justify-content: space-between;
  gap: 18px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  font-size: 20px;
  overflow-wrap: anywhere;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(70px, 1fr));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
  background: #ffffff;
}

.segmented button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.is-selected {
  background: var(--ink);
  color: #ffffff;
}

.invoice-form {
  display: grid;
  gap: 16px;
  padding: 16px;
  overflow: auto;
  max-height: calc(100vh - 108px);
}

.form-section {
  display: grid;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.form-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.form-section h3 {
  font-size: 16px;
}

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

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

.form-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.section-title-row {
  justify-content: space-between;
}

.line-add-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.line-add-control select {
  min-height: 40px;
  max-width: 190px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 7px 30px 7px 10px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
}

.column-settings {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.column-settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.column-settings-heading strong {
  font-size: 13px;
}

.column-settings-heading .button {
  min-height: 36px;
  padding: 7px 10px;
  font-size: 12px;
}

.extra-column-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.extra-column-field {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  align-items: end;
  gap: 6px;
}

.extra-column-empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.remove-column {
  width: 36px;
  height: 38px;
  border: 1px solid #f4b5ae;
  border-radius: var(--radius);
  background: #fff4f2;
  color: var(--danger);
  font-size: 18px;
  font-weight: 900;
}

.compact-field span {
  font-size: 11px;
}

.compact-field input {
  min-height: 38px;
  padding: 7px 9px;
  font-size: 13px;
}

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

.asset-upload {
  min-width: 0;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.asset-upload-heading strong,
.asset-upload-heading span {
  display: block;
}

.asset-upload-heading strong {
  font-size: 13px;
}

.asset-upload-heading span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.asset-upload-preview {
  height: 104px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.asset-upload-preview span {
  color: var(--muted);
  font-size: 12px;
}

.asset-upload-preview img {
  width: 100%;
  height: 100%;
  padding: 8px;
  object-fit: contain;
}

.asset-upload-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.asset-upload-actions .button {
  min-height: 36px;
  padding-inline: 10px;
  font-size: 12px;
}

.asset-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.asset-remove-button {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid #f4b5ae;
  border-radius: var(--radius);
  background: #fff4f2;
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
}

.line-table {
  display: grid;
  gap: 10px;
}

.line-row {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.line-row-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}

.line-row-toolbar strong {
  margin-right: auto;
  font-size: 13px;
}

.line-row-toolbar select {
  width: 132px;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 7px 30px 7px 9px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
}

.line-row-fields {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 9px;
  align-items: end;
}

.line-row-field {
  min-width: 0;
  grid-column: span 2;
  display: grid;
  gap: 5px;
}

.line-row-field > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.line-field-description {
  grid-column: span 4;
}

.line-field-wide {
  grid-column: 1 / -1;
}

.line-row-field input,
.line-row-field textarea {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
}

.line-row-field textarea {
  line-height: 1.35;
  resize: vertical;
}

.line-row-field input:focus,
.line-row-field textarea:focus,
.line-row-toolbar select:focus {
  border-color: var(--blue);
  outline: none;
  box-shadow: 0 0 0 3px rgba(7, 95, 168, 0.16);
}

.line-row-wide.is-section textarea {
  font-weight: 900;
}

.line-total {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--surface-muted);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.remove-line {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border: 1px solid #f4b5ae;
  border-radius: var(--radius);
  background: #fff4f2;
  color: var(--danger);
  font-weight: 900;
}

.preview-panel {
  position: sticky;
  top: 92px;
  align-self: start;
  max-height: calc(100vh - 108px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  overflow: auto;
}

.preview-actions {
  justify-content: space-between;
  flex-wrap: wrap;
}

.preview-zoom,
.preview-record-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-zoom {
  min-height: 40px;
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.zoom-button {
  width: 32px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.zoom-button:hover {
  background: #e6f2ff;
  color: var(--blue);
}

.zoom-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.preview-zoom output {
  width: 44px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.preview-stage {
  position: relative;
  width: 100%;
  flex: 0 0 auto;
  margin: 0 auto;
  overflow: hidden;
  background: #e9edf1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.invoice-preview {
  position: absolute;
  top: 0;
  left: 0;
  width: 794px;
  min-height: 1123px;
  margin: 0;
  overflow: hidden;
  background: #ffffff;
  border: 0;
  border-radius: 0;
  box-shadow: var(--shadow);
  color: #2a2a2e;
  transform: scale(0.56);
  transform-origin: top left;
}

.andou-top {
  min-height: 148px;
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 28px;
  align-items: center;
  padding: 30px 48px 28px;
  background: var(--blue);
  color: #ffffff;
}

.andou-brand {
  display: grid;
  justify-items: center;
  gap: 14px;
}

.andou-logo {
  position: relative;
  width: 52px;
  height: 52px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  overflow: hidden;
}

.andou-logo::before {
  content: "A";
  position: absolute;
  left: 11px;
  top: 1px;
  color: #ffffff;
  font-size: 42px;
  font-weight: 900;
  line-height: 1;
}

.andou-logo::after {
  content: "";
  position: absolute;
  right: 7px;
  top: -5px;
  width: 17px;
  height: 66px;
  background: repeating-linear-gradient(65deg, #ffffff 0 4px, transparent 4px 8px);
  transform: rotate(-20deg);
}

.andou-brand-name {
  color: #ffffff;
  font-size: 20px;
  letter-spacing: 4px;
  text-transform: uppercase;
}

.andou-title {
  font-size: clamp(40px, 5vw, 62px);
  font-weight: 400;
  line-height: 1.25;
  text-transform: uppercase;
}

.invoice-sheet-body {
  padding: 26px 48px 34px;
}

.model-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 36px;
  margin-bottom: 54px;
  font-size: 17px;
}

.model-meta strong {
  font-weight: 800;
}

.model-meta .date-block {
  justify-self: end;
}

.model-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-bottom: 34px;
}

.model-table th {
  padding: 12px 8px;
  background: var(--olive);
  color: #ffffff;
  border: 1px solid var(--olive);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  text-transform: uppercase;
}

.model-table td {
  padding: 11px 9px;
  border: 1px solid #333333;
  font-size: 16px;
  line-height: 1.35;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.model-table .model-wide-row td {
  width: auto;
  text-align: left;
}

.model-table .model-wide-row.is-section td {
  padding-top: 9px;
  padding-bottom: 9px;
  background: #f2f4e8;
  color: #39461f;
  font-weight: 900;
  text-transform: uppercase;
}

.model-table .model-wide-row.is-note td {
  padding-top: 8px;
  padding-bottom: 8px;
  font-style: italic;
}

.model-table th:first-child,
.model-table td:first-child {
  text-align: left;
}

.model-table.has-many-columns th {
  padding: 9px 5px;
  font-size: 11px;
}

.model-table.has-many-columns td {
  padding: 8px 5px;
  font-size: 12px;
}

.model-totals {
  display: grid;
  justify-content: end;
  margin-bottom: 34px;
  font-size: 16px;
}

.model-total-line {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  min-width: 268px;
  padding: 3px 0;
}

.model-total-line span {
  text-align: right;
}

.model-total-line strong {
  font-weight: 500;
}

.model-total-line.final {
  min-width: 284px;
  margin-top: 1px;
  padding: 5px 12px;
  background: var(--olive);
  color: #ffffff;
}

.model-total-line.final strong {
  font-weight: 900;
}

.amount-words {
  margin: 0 0 24px;
  font-size: 16px;
}

.amount-words strong {
  font-weight: 900;
  text-transform: uppercase;
}

.bank-signature {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 30px;
  align-items: start;
  margin-bottom: 54px;
}

.bank-signature h3 {
  margin: 0 0 9px;
  font-size: 18px;
}

.bank-signature p {
  margin: 4px 0;
  font-size: 16px;
}

.signature-title {
  margin-top: 28px;
  font-size: 17px;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.approval-section.has-assets .signature-title {
  margin-top: 0;
}

.approval-visuals {
  position: relative;
  width: min(100%, 220px);
  height: 92px;
  margin: 2px auto 0;
}

.approval-visuals img {
  position: absolute;
  left: 50%;
  bottom: 0;
  display: block;
  object-fit: contain;
}

.electronic-signature {
  z-index: 2;
  width: 150px;
  height: 66px;
  transform: translateX(-62%);
}

.electronic-stamp {
  z-index: 1;
  width: 96px;
  height: 92px;
  transform: translateX(12%);
  opacity: 0.92;
}

.approval-visuals.has-signature:not(.has-stamp) .electronic-signature,
.approval-visuals.has-stamp:not(.has-signature) .electronic-stamp {
  transform: translateX(-50%);
}

.legal-footer {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.55;
}

.sheet-footer {
  position: absolute;
  left: 48px;
  right: 48px;
  bottom: 22px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 18px;
  font-size: 14px;
}

.social-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.social-dots span {
  width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #000000;
  color: #ffffff;
  font-size: 10px;
  font-weight: 900;
}

.handle-shape {
  justify-self: end;
  min-width: 132px;
  padding: 10px 12px;
  border-radius: 44px 0 0 44px;
  background: var(--charcoal);
  color: #ffffff;
  text-align: center;
}

.empty-state {
  padding: 24px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.empty-state strong,
.empty-state span {
  display: block;
}

.empty-state span {
  margin-top: 4px;
}

@media (max-width: 1500px) {
  .workspace {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .workspace.is-list-collapsed {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .preview-panel {
    grid-column: 1 / -1;
  }
}

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

  .dashboard-insights,
  .dashboard-details {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
  }

  .app-navigation {
    position: static;
    width: 100%;
    height: auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 18px;
    padding: 10px 14px;
  }

  .nav-brand {
    padding: 0;
    border-bottom: 0;
  }

  .nav-links {
    display: flex;
    justify-content: center;
    margin: 0;
  }

  .nav-link {
    width: auto;
  }

  .nav-footer {
    margin: 0;
    padding: 0;
    border-top: 0;
    text-align: right;
  }

  .app-main {
    width: 100%;
  }
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .workspace.is-list-collapsed {
    grid-template-columns: 1fr;
  }

  .workspace.is-list-collapsed .invoice-sidebar-content {
    display: flex;
  }

  .workspace.is-list-collapsed .invoice-sidebar-heading {
    justify-content: space-between;
    padding: 6px 6px 6px 12px;
  }

  .workspace.is-list-collapsed .invoice-sidebar-heading strong {
    display: block;
  }

  .invoice-sidebar-heading button {
    display: none;
  }

  .preview-panel {
    position: static;
    max-height: none;
  }

  .dashboard-view {
    padding: 14px 10px;
  }

  .dashboard-intro {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-overview {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .invoice-list,
  .invoice-form {
    max-height: none;
  }

  .panel-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .segmented {
    width: 100%;
  }

  .form-grid.two,
  .form-grid.three,
  .form-grid.four,
  .approval-upload-grid {
    grid-template-columns: 1fr;
  }

  .extra-column-list {
    grid-template-columns: 1fr;
  }

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

  .line-row-field {
    grid-column: span 1;
  }

  .line-field-description,
  .line-field-wide,
  .line-field-total {
    grid-column: 1 / -1;
  }

  .andou-top {
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 26px 22px;
    text-align: center;
  }

  .andou-title {
    font-size: 40px;
  }

  .invoice-sheet-body {
    padding: 22px;
  }

  .model-meta,
  .bank-signature,
  .sheet-footer {
    grid-template-columns: 1fr;
  }

  .model-meta .date-block,
  .handle-shape {
    justify-self: start;
  }

  .sheet-footer {
    position: static;
    margin-top: 28px;
  }
}

@media (max-width: 560px) {
  .app-navigation {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .nav-brand {
    justify-content: center;
  }

  .nav-links {
    width: 100%;
  }

  .nav-link {
    flex: 1;
    justify-content: center;
  }

  .nav-footer {
    display: none;
  }

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

  .bar-chart {
    gap: 4px;
  }

  .dashboard-panel {
    padding: 14px;
  }

  .recent-table th:nth-child(3),
  .recent-table td:nth-child(3),
  .recent-table th:nth-child(4),
  .recent-table td:nth-child(4) {
    display: none;
  }

  .recent-table th:nth-child(1) { width: 24%; }
  .recent-table th:nth-child(2) { width: 30%; }
  .recent-table th:nth-child(5) { width: 38%; }
  .recent-table th:nth-child(6) { width: 8%; }

  .button {
    flex: 1 1 auto;
  }

  .line-add-control {
    width: 100%;
  }

  .line-add-control select {
    max-width: none;
    flex: 1 1 auto;
  }

  .line-row-fields {
    grid-template-columns: 1fr;
  }

  .line-row-field,
  .line-field-description,
  .line-field-wide,
  .line-field-total {
    grid-column: 1;
  }

  .line-row-toolbar {
    flex-wrap: wrap;
  }

  .remove-line {
    width: 100%;
  }

  .andou-title {
    font-size: 34px;
  }

  .model-table th,
  .model-table td {
    font-size: 12px;
    padding-left: 5px;
    padding-right: 5px;
  }

  .model-total-line {
    min-width: 0;
  }
}

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

@media print {
  html,
  body {
    width: 210mm;
    height: 296mm;
    min-height: 0;
    margin: 0;
    overflow: hidden !important;
    background: #ffffff;
  }

  .invoice-preview,
  .invoice-preview *,
  .invoice-preview::before,
  .invoice-preview::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .app-navigation,
  .topbar,
  .dashboard-view,
  .invoice-sidebar,
  .editor-panel,
  .preview-actions {
    display: none !important;
  }

  .app-shell,
  .app-main,
  #invoiceView,
  .workspace,
  .preview-panel {
    display: block;
    width: 210mm;
    height: 296mm;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }

  .preview-panel {
    position: static;
    max-height: none;
    overflow: hidden;
    border: 0;
    box-shadow: none;
  }

  .preview-stage {
    width: 210mm !important;
    height: 296mm !important;
    margin: 0;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: #ffffff;
  }

  .invoice-preview {
    position: relative;
    top: auto;
    left: auto;
    width: 210mm;
    height: 296mm;
    min-height: 0;
    overflow: hidden;
    transform: none !important;
    border: 0;
    box-shadow: none;
    border-radius: 0;
  }

  .andou-top {
    min-height: 148px;
    grid-template-columns: 1fr 1.2fr;
    gap: 28px;
    align-items: center;
    justify-items: stretch;
    padding: 30px 48px 28px;
    background: var(--blue) !important;
    box-shadow: inset 0 0 0 1000px var(--blue);
    color: #ffffff !important;
    text-align: left;
  }

  .andou-brand {
    justify-items: center;
  }

  .andou-logo {
    border-color: #ffffff !important;
  }

  .andou-logo::before,
  .andou-logo::after,
  .andou-brand-name,
  .andou-title {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color: #ffffff !important;
  }

  .andou-title {
    font-size: 62px;
  }

  .invoice-sheet-body {
    padding: 26px 48px 34px;
  }

  .model-meta {
    grid-template-columns: 1fr 1fr;
    gap: 36px;
    margin-bottom: 54px;
    font-size: 17px;
  }

  .model-meta .date-block {
    justify-self: end;
  }

  .model-table th {
    padding: 12px 8px;
    background: var(--olive) !important;
    box-shadow: inset 0 0 0 1000px var(--olive);
    color: #ffffff !important;
    border-color: var(--olive);
    font-size: 14px;
  }

  .model-table td {
    padding: 11px 9px;
    font-size: 16px;
  }

  .model-total-line {
    min-width: 268px;
  }

  .model-total-line.final {
    min-width: 284px;
    background: var(--olive) !important;
    box-shadow: inset 0 0 0 1000px var(--olive);
    color: #ffffff !important;
  }

  .bank-signature {
    grid-template-columns: 1.2fr 1fr;
    gap: 30px;
  }

  .sheet-footer {
    position: absolute;
    left: 48px;
    right: 48px;
    bottom: 22px;
    grid-template-columns: 1fr auto 1fr;
    gap: 18px;
    margin-top: 0;
  }

  .social-dots span {
    background: #000000 !important;
    box-shadow: inset 0 0 0 100px #000000;
    color: #ffffff !important;
  }

  .handle-shape {
    justify-self: end;
    background: var(--charcoal) !important;
    box-shadow: inset 0 0 0 100px var(--charcoal);
    color: #ffffff !important;
  }
}

/* Version 2: operational workspace and document system */
.icon-command {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
}

.icon-command:disabled {
  cursor: default;
  opacity: .4;
}

.autosave-indicator {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.preview-toggle {
  display: none;
}

.drawer-close {
  display: none;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 22px;
}

.sync-state::before {
  content: "";
  width: 7px;
  height: 7px;
  display: inline-block;
  margin-right: 6px;
  border-radius: 50%;
  background: #98a5ad;
}

.sync-state[data-state="online"]::before { background: #49d18d; }
.sync-state[data-state="error"]::before { background: #ff7167; }
.sync-state[data-state="offline"]::before { background: #f2b84b; }

.nav-footer small {
  color: var(--nav-muted);
  font-size: 10px;
  overflow-wrap: anywhere;
}

.period-control,
.reports-toolbar > div:last-child {
  display: flex;
  align-items: center;
  gap: 8px;
}

.period-control label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.period-control select,
.reports-toolbar select {
  min-height: 40px;
  padding: 0 34px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
}

.aging-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.aging-strip > div {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.aging-strip > div:last-child { border-right: 0; }
.aging-strip span { color: var(--muted); font-size: 11px; font-weight: 800; }
.aging-strip strong { font-size: 15px; overflow-wrap: anywhere; }

.bar-item {
  height: 100%;
  display: grid;
  grid-template-rows: 20px 1fr 24px;
  gap: 5px;
  min-width: 0;
  text-align: center;
}

.bar-value {
  color: var(--muted);
  font-size: 9px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-item .bar-track {
  align-items: end;
  border-radius: 4px 4px 0 0;
  background: #f1f4f6;
  overflow: hidden;
}

.bar-item .bar-track i {
  width: min(42px, 64%);
  min-height: 4px;
  display: block;
  margin: 0 auto;
  border-radius: 4px 4px 0 0;
  background: var(--blue);
}

.bar-item small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-breakdown > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e9edf1;
  color: #4d5964;
  font-size: 10px;
  font-weight: 900;
  white-space: nowrap;
}

.status-finalized,
.status-sent,
.status-viewed { background: #e5f2ff; color: var(--blue-dark); }
.status-paid { background: #e3f5ec; color: var(--success); }
.status-partial { background: #fff1d8; color: #81500a; }
.status-overdue,
.status-void { background: #ffebe8; color: var(--danger); }

.recent-table td strong,
.recent-table td small { display: block; }
.recent-table td small { margin-top: 2px; color: var(--muted); font-size: 10px; }

.table-open {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--blue);
  font-size: 18px;
}

.followup-list > button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.followup-list > button:hover { border-color: var(--blue); }
.followup-list > button span { min-width: 0; }
.followup-list > button strong,
.followup-list > button small { display: block; }
.followup-list > button small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.followup-list > button b { color: var(--danger); font-size: 12px; white-space: nowrap; }

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.invoice-card {
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.invoice-card:hover,
.invoice-card.is-selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(7,95,168,.10);
}

.invoice-card > div,
.invoice-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.invoice-card > div strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-card > span { color: var(--muted); font-size: 11px; }
.invoice-card footer small { color: var(--muted); font-size: 9px; font-weight: 900; }
.invoice-card footer b { font-size: 13px; }

.document-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.document-actions .button {
  min-height: 34px;
  padding-inline: 10px;
  font-size: 11px;
}

.lock-note {
  margin: 4px 0 0;
  color: var(--success);
  font-size: 11px;
  font-weight: 800;
}

.status-flow {
  display: flex;
  min-width: 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}

.status-flow button {
  position: relative;
  flex: 1 0 auto;
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
}

.status-flow button.is-complete { color: var(--blue); }
.status-flow button.is-current { background: #e8f3fc; color: var(--blue-dark); }
.status-flow button:disabled { cursor: default; }

.editable-fields {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.editable-fields:disabled {
  opacity: .76;
}

.editable-fields:disabled input,
.editable-fields:disabled select,
.editable-fields:disabled textarea { background: #f5f6f7; }

.section-title-row {
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.section-title-row > div > h3 { margin: 0; }
.section-hint { color: var(--muted); font-size: 11px; }

.client-picker { max-width: 440px; margin-bottom: 12px; }
.field-span-two { grid-column: span 2; }

.line-add-control,
.catalog-shortcut,
.column-settings-heading {
  display: flex;
  align-items: center;
  gap: 8px;
}

.line-add-control select,
.catalog-shortcut select {
  min-width: 0;
  min-height: 40px;
  padding: 0 34px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
}

.catalog-shortcut { margin-bottom: 12px; }
.catalog-shortcut select { flex: 1; }

.column-settings {
  margin-bottom: 14px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafb;
}

.column-settings summary {
  cursor: pointer;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
}

.column-settings[open] summary { margin-bottom: 14px; }
.column-settings-heading { justify-content: space-between; margin-bottom: 12px; }

.extra-column-list { display: grid; gap: 7px; margin-top: 10px; }
.extra-column-row {
  display: grid;
  grid-template-columns: 28px minmax(120px, 1fr) 130px 32px 32px 32px;
  gap: 6px;
  align-items: center;
}

.extra-column-row input,
.extra-column-row select,
.extra-column-row button {
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
}

.extra-column-row input,
.extra-column-row select { padding: 5px 8px; }
.extra-column-row button:last-child { color: var(--danger); }
.drag-handle { color: var(--muted); font-size: 11px; font-weight: 900; text-align: center; }

.line-editor {
  min-width: 780px;
  display: grid;
  grid-template-columns: 42px minmax(190px, 1.8fr) minmax(80px, .7fr) 80px 110px 84px 76px repeat(auto-fit, minmax(100px, 1fr)) minmax(110px, .9fr) 38px;
  gap: 8px;
  align-items: end;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.line-table { overflow-x: auto; padding-bottom: 3px; }
.line-editor label { min-width: 0; display: grid; gap: 5px; }
.line-editor label > span { color: var(--muted); font-size: 10px; font-weight: 800; }
.line-editor input,
.line-editor textarea {
  width: 100%;
  min-width: 0;
  min-height: 39px;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
}

.line-editor textarea { resize: vertical; }
.line-order { display: grid; grid-template-rows: 26px 22px 26px; justify-items: center; align-items: center; }
.line-order button,
.line-remove {
  width: 30px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--muted);
}
.line-remove { height: 39px; color: var(--danger); font-size: 18px; }
.line-description textarea { min-height: 60px; }
.line-editor .line-total { min-height: 39px; font-size: 12px; }

.line-editor.line-section,
.line-editor.line-note {
  min-width: 520px;
  grid-template-columns: 42px 1fr 38px;
  align-items: center;
}
.line-editor.line-section textarea { font-weight: 900; }
.line-editor.line-note textarea { font-style: italic; }

.payment-entry {
  display: grid;
  grid-template-columns: 130px minmax(120px, 1fr) 150px minmax(120px, 1fr) auto;
  gap: 9px;
  align-items: end;
}

.payment-list,
.attachment-list { display: grid; gap: 7px; margin-top: 12px; }

.payment-row,
.attachment-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfc;
  font-size: 11px;
}

.payment-row > span:first-child,
.attachment-row > span { min-width: 0; flex: 1; }
.payment-row strong,
.payment-row small,
.attachment-row strong,
.attachment-row small { display: block; }
.payment-row small,
.attachment-row small { margin-top: 2px; color: var(--muted); }
.payment-row button,
.attachment-row button,
.attachment-row a { border: 0; background: transparent; color: var(--blue); font-weight: 900; text-decoration: none; }
.payment-row.is-cancelled { opacity: .55; text-decoration: line-through; }

.attachments-section input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.inline-empty { margin: 0; padding: 10px 0; color: var(--muted); font-size: 11px; }

body.invoice-sidebar-collapsed .workspace {
  grid-template-columns: 52px minmax(620px, 1.45fr) minmax(380px, 500px);
}

body .workspace.is-empty {
  grid-template-columns: minmax(210px, 240px) minmax(0, 1fr);
}

body.invoice-sidebar-collapsed .workspace.is-empty {
  grid-template-columns: 52px minmax(0, 1fr);
}
body.invoice-sidebar-collapsed .invoice-sidebar-heading { justify-content: center; padding: 6px; }
body.invoice-sidebar-collapsed .invoice-sidebar-heading strong,
body.invoice-sidebar-collapsed .invoice-sidebar-content { display: none; }

.management-view {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(250px, 330px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.management-sidebar,
.management-content,
.settings-section {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.management-heading,
.reports-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.management-heading h2,
.reports-toolbar h2,
.record-form h2,
.settings-section h2 { margin: 0; font-size: 21px; }
.record-list { display: grid; gap: 8px; margin-top: 14px; }

.record-card {
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.record-card:hover,
.record-card.is-selected { border-color: var(--blue); background: #f5faff; }
.record-card span { color: var(--muted); font-size: 11px; }
.record-form { max-width: 1000px; }
.client-insights { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 20px; }
.client-insights > div { display: grid; gap: 4px; padding: 13px; border: 1px solid var(--line); border-radius: 6px; background: #f8fafb; }
.client-insights span { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.client-insights strong { overflow-wrap: anywhere; }

.reports-view,
.settings-view { flex: 1; padding: 20px; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.report-wide { grid-column: 1 / -1; }
.report-table-wrap { margin-top: 14px; overflow-x: auto; }
.report-table-wrap table { width: 100%; border-collapse: collapse; }
.report-table-wrap th,
.report-table-wrap td { padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 11px; text-align: left; }
.report-table-wrap th { color: var(--muted); font-size: 9px; text-transform: uppercase; }

.settings-layout { max-width: 1180px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 0 auto; }
.settings-section:last-child,
.settings-wide { grid-column: 1 / -1; }
.platform-access-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; margin-top: 18px; }
.platform-access-columns > section { min-width: 0; }
.platform-access-columns h3 { margin: 0 0 10px; font-size: 16px; }
.platform-access-columns .operation-row { align-items: flex-start; }
.platform-access-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.platform-access-actions .button { min-height: 36px; padding: 7px 10px; font-size: 12px; }
.platform-access-message { color: var(--muted); font-size: 12px; }
.users-list,
.audit-list,
.backup-list,
.notification-list,
.error-list { display: grid; gap: 6px; margin-top: 12px; }
.users-list > div,
.audit-list > div,
.operation-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.users-list strong,
.users-list small,
.audit-list strong,
.audit-list small,
.operation-row strong,
.operation-row small { display: block; }
.users-list small,
.audit-list small,
.operation-row small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.users-list b { align-self: center; color: var(--blue); font-size: 10px; text-transform: uppercase; }
.operation-row b { color: var(--olive-dark); font-size: 10px; text-transform: uppercase; }
.user-row { display: grid !important; grid-template-columns: minmax(150px, 1fr) 130px auto auto auto; align-items: center; }
.user-row select { min-width: 0; padding: 7px; border: 1px solid var(--line-strong); border-radius: 5px; background: #fff; }
.active-toggle { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 800; }
.operations-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.operations-summary > div { padding: 11px; border: 1px solid var(--line); border-radius: 6px; background: #f8fafb; }
.operations-summary strong,
.operations-summary span { display: block; }
.operations-summary strong { font-size: 20px; }
.operations-summary span { margin-top: 2px; color: var(--muted); font-size: 10px; }
.operations-summary > small { grid-column: 1 / -1; color: var(--muted); }
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.control-grid h3,
.share-history h3 { margin: 14px 0 6px; font-size: 13px; }
.nav-signout { padding: 0; border: 0; background: transparent; color: #c8d4da; font: inherit; font-size: 11px; text-align: left; text-decoration: underline; cursor: pointer; }

.app-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.app-dialog::backdrop { background: rgba(18, 29, 35, .52); }
.app-dialog form { padding: 22px; }
.app-dialog h2 { margin: 0 0 8px; }
.app-dialog p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.credential-dialog > div { padding: 24px; }
.credential-dialog output { display: block; margin: 18px 0; padding: 14px; border: 1px dashed var(--blue); border-radius: 6px; background: #f5faff; color: var(--blue); font-size: 18px; font-weight: 900; text-align: center; word-break: break-all; }
.sync-conflict-dialog { width: min(520px, calc(100vw - 32px)); }
.sync-conflict-dialog > div { display: grid; gap: 10px; padding: 24px; }
.sync-conflict-dialog h2,
.sync-conflict-dialog p { margin: 0; }
.sync-conflict-dialog .sync-conflict-message { min-height: 18px; color: var(--blue); font-size: 12px; font-weight: 700; }
.sync-conflict-actions { display: grid; gap: 8px; margin-top: 4px; }
.sync-conflict-actions .text-button { min-height: 40px; }
.share-dialog { width: min(560px, calc(100vw - 32px)); }
.share-result { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; margin-top: 14px; padding: 12px; border: 1px solid var(--line); background: #f8fafb; }
.share-result .field { margin: 0; }
.share-history { margin-top: 16px; padding-top: 8px; border-top: 1px solid var(--line); }
.is-read-only .editable-fields { opacity: .82; }
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 8px; width: min(360px, calc(100vw - 40px)); }
.toast { padding: 12px 14px; border-left: 4px solid var(--blue); border-radius: 6px; background: #fff; box-shadow: 0 12px 32px rgba(18,29,35,.2); font-size: 12px; font-weight: 800; }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }

.auth-dialog { width: min(460px, calc(100vw - 28px)); }
.auth-dialog form { display: grid; gap: 12px; text-align: center; }
.auth-dialog h2,
.auth-dialog p { margin: 0; }
.auth-dialog .field { margin-top: 6px; text-align: left; }
.auth-dialog .button { width: 100%; }
.auth-mark { width: 52px; height: 52px; display: grid; place-items: center; margin: 0 auto 4px; border-radius: 50%; background: var(--nav); color: #fff; font-size: 28px; font-weight: 900; }
.auth-error { min-height: 18px; color: var(--danger) !important; font-size: 11px; font-weight: 800; }

/* Dynamic A4 document preview */
.invoice-preview {
  min-height: 1123px;
  height: auto;
  overflow: visible;
  transform: scale(var(--preview-scale, .56));
}

.document-hero {
  min-height: 158px;
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  align-items: center;
  gap: 28px;
  padding: 28px 48px;
  background: var(--blue);
  color: #fff;
}

.document-brand { display: grid; justify-items: center; gap: 11px; }
.document-brand strong { font-size: 19px; letter-spacing: 4px; }
.document-monogram { width: 52px; height: 52px; display: grid; place-items: center; border: 2px solid #fff; border-radius: 50%; font-size: 34px; font-weight: 900; }
.document-hero h2 { margin: 0; font-size: 52px; font-weight: 500; line-height: 1.04; overflow-wrap: anywhere; }

.document-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 36px;
  padding: 30px 48px 26px;
  font-size: 14px;
}
.document-meta > div { display: grid; align-content: start; gap: 4px; }
.document-meta > div:last-child { justify-self: end; text-align: right; }

.fiscal-readiness-note { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 14px; margin: 0 0 18px; padding: 12px 14px; border: 1px solid #dec779; border-left: 4px solid #a66a00; border-radius: 6px; background: #fff9e8; color: #493714; font-size: 13px; line-height: 1.5; }
.fiscal-readiness-note strong { white-space: nowrap; }
@media (max-width: 820px) { .fiscal-readiness-note { grid-template-columns: 1fr; gap: 4px; } .fiscal-readiness-note strong { white-space: normal; } }

.document-lines {
  width: calc(100% - 96px);
  margin: 22px 48px 24px;
  border-collapse: collapse;
  table-layout: fixed;
}
.document-lines th { padding: 10px 6px; border: 1px solid var(--olive); background: var(--olive); color: #fff; font-size: 10px; text-align: center; text-transform: uppercase; overflow-wrap: break-word; word-break: normal; }
.document-lines th:first-child,
.document-lines td:first-child { width: 34%; text-align: left; }
.document-lines td { padding: 9px 6px; border: 1px solid #454545; font-size: 11px; line-height: 1.35; vertical-align: top; overflow-wrap: break-word; word-break: normal; }
.document-lines td:not(:first-child) { white-space: nowrap; overflow-wrap: normal; }
.document-section-row td { background: #eef1e5; color: #3d4b23; font-weight: 900; text-transform: uppercase; }
.document-note-row td { background: #f7f8f9; font-style: italic; white-space: normal; }

.document-summary { display: flex; justify-content: flex-end; padding: 0 48px 24px; }
.document-summary dl { width: min(360px, 55%); margin: 0; }
.document-summary dl > div { display: grid; grid-template-columns: 1fr auto; gap: 20px; padding: 4px 8px; font-size: 13px; }
.document-summary dt { text-align: right; }
.document-summary dd { margin: 0; font-weight: 800; white-space: nowrap; }
.document-summary .summary-total { margin-top: 4px; padding: 8px 10px; background: var(--olive); color: #fff; font-size: 15px; }
.document-summary .summary-balance { color: var(--blue-dark); font-size: 15px; font-weight: 900; }

.invoice-preview > .amount-words,
.document-notes,
.document-bottom,
.integrity-seal,
.document-footer { margin-left: 48px; margin-right: 48px; }
.invoice-preview > .amount-words { margin-bottom: 22px; font-size: 13px; }
.document-notes { margin-bottom: 22px; padding: 12px; border-left: 3px solid var(--olive); background: #f8f9f4; font-size: 12px; }
.document-notes p { margin: 4px 0 0; }
.document-bottom { display: grid; grid-template-columns: 1.2fr 1fr; gap: 34px; margin-bottom: 26px; break-inside: avoid; }
.document-bottom h3 { margin: 0 0 7px; font-size: 15px; }
.document-bottom p { margin: 0; font-size: 12px; line-height: 1.55; }
.document-approval { min-height: 110px; text-align: center; }
.approval-assets { position: relative; width: 210px; height: 90px; margin: 4px auto 0; }
.approval-assets img { position: absolute; left: 50%; bottom: 0; object-fit: contain; }
.signature-image { z-index: 2; width: 145px; height: 66px; transform: translateX(-65%); }
.stamp-image { z-index: 1; width: 90px; height: 90px; transform: translateX(12%); opacity: .9; }
.approval-assets .signature-image:only-child,
.approval-assets .stamp-image:only-child { transform: translateX(-50%); }
.integrity-seal { margin-top: 16px; padding: 8px 10px; border: 1px solid #c9d6df; background: #f3f8fb; color: #425565; font-size: 9px; break-inside: avoid; }
.document-footer { margin-top: 30px; padding: 16px 0 22px; border-top: 1px solid var(--line); font-size: 10px; break-inside: avoid; }
.document-footer p { margin: 0 0 18px; line-height: 1.5; }
.document-footer > div { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.document-footer > div strong { padding: 8px 12px; border-radius: 22px 0 0 22px; background: var(--charcoal); color: #fff; }

/* Finance operations, guidance and accessibility */
.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 200;
  padding: 10px 14px;
  border-radius: 6px;
  background: #fff;
  color: var(--blue-dark);
  font-weight: 800;
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }
:focus-visible { outline: 3px solid #f3b61f; outline-offset: 2px; }
.field > span,
.section-hint,
.record-card span,
.users-list small,
.audit-list small,
.operation-row small { font-size: 13px; }

.cash-panel { padding: 18px; }
.cash-forecast { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 12px; }
.cash-forecast-item { position: relative; min-width: 0; display: grid; gap: 5px; padding: 13px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; }
.cash-forecast-item span { color: var(--muted); font-size: 13px; font-weight: 800; }
.cash-forecast-item strong { overflow-wrap: anywhere; font-size: 16px; }
.cash-forecast-item i { height: 4px; max-width: 100%; border-radius: 2px; background: var(--charcoal); }
.cash-forecast-item.primary i { background: var(--blue); }
.cash-forecast-item.danger i { background: var(--danger); }

.banking-view { width: 100%; max-width: 1500px; display: grid; gap: 16px; margin: 0 auto; padding: 20px; }
.banking-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 22px; }
.banking-toolbar h2 { margin: 0; font-size: 25px; }
.banking-toolbar p:last-child { max-width: 700px; margin: 7px 0 0; color: var(--muted); }
.banking-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
#bankFileInput { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.bank-summary { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.bank-summary article { min-width: 0; display: grid; gap: 5px; padding: 16px; border-right: 1px solid var(--line); }
.bank-summary article:last-child { border-right: 0; }
.bank-summary span { color: var(--muted); font-size: 13px; font-weight: 800; }
.bank-summary strong { overflow-wrap: anywhere; font-size: 20px; }
.banking-content { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.banking-filter { display: grid; grid-template-columns: minmax(170px, .35fr) minmax(240px, 1fr); gap: 10px; margin-bottom: 14px; }
.bank-transaction-list { display: grid; gap: 8px; }
.bank-transaction { display: grid; grid-template-columns: minmax(210px, 1.4fr) minmax(140px, .5fr) minmax(260px, 1.2fr) auto; align-items: center; gap: 14px; padding: 13px; border: 1px solid var(--line); border-radius: 6px; }
.bank-transaction.is-debit { background: #fafafa; }
.bank-transaction-main { min-width: 0; display: grid; gap: 2px; }
.bank-transaction-main span,
.bank-transaction-main small,
.bank-match-control small,
.bank-match-result small { color: var(--muted); font-size: 12px; }
.bank-transaction-main strong { overflow-wrap: anywhere; }
.bank-transaction > b { text-align: right; white-space: nowrap; }
.bank-transaction.is-debit > b { color: var(--danger); }
.bank-match-control,
.bank-match-result { min-width: 0; display: grid; gap: 4px; }
.bank-match-control select { width: 100%; min-width: 0; padding: 9px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; }
.bank-row-actions { display: flex; align-items: center; gap: 8px; }
.bank-empty { padding: 40px; }

.reports-toolbar > div:last-child { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.reports-toolbar select { min-height: 40px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; }
.report-table-wrap th,
.report-table-wrap td { font-size: 13px; }
.report-table-wrap th { font-size: 12px; }

.notification-row { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto; }
.notification-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.onboarding-list { display: grid; gap: 10px; padding: 0; list-style: none; }
.onboarding-list li { display: grid; grid-template-columns: 32px 1fr; gap: 10px; align-items: start; }
.onboarding-list li > span { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--nav); color: #fff; font-weight: 900; }
.onboarding-list strong,
.onboarding-list small { display: block; }
.onboarding-list small { margin-top: 2px; color: var(--muted); font-size: 13px; }
.help-dialog { width: min(780px, calc(100vw - 32px)); }
.help-dialog > div { padding: 24px; }
.help-dialog .drawer-close { display: grid; flex: 0 0 auto; }
.guide-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.guide-grid section { padding: 15px; border: 1px solid var(--line); border-radius: 6px; background: #f8fafb; }
.guide-grid p { margin: 5px 0 0; color: var(--muted); }

@media (max-width: 1500px) {
  .workspace { grid-template-columns: 52px minmax(590px, 1fr) minmax(380px, 470px); }
  .workspace .invoice-sidebar-heading { justify-content: center; padding: 6px; }
  .workspace .invoice-sidebar-heading strong,
  .workspace .invoice-sidebar-content { display: none; }
  body:not(.invoice-sidebar-collapsed) .workspace { grid-template-columns: minmax(200px, 220px) minmax(590px, 1fr); }
  body:not(.invoice-sidebar-collapsed) .workspace .invoice-sidebar-heading { justify-content: space-between; padding: 6px 6px 6px 12px; }
  body:not(.invoice-sidebar-collapsed) .workspace .invoice-sidebar-heading strong,
  body:not(.invoice-sidebar-collapsed) .workspace .invoice-sidebar-content { display: flex; }
  body:not(.invoice-sidebar-collapsed) .workspace .invoice-sidebar-content { flex-direction: column; }
  .preview-toggle { display: inline-flex; }
  .drawer-close { display: grid; }
  .preview-panel {
    position: fixed;
    top: 0;
    right: 16px;
    bottom: auto;
    z-index: 40;
    width: min(560px, calc(100vw - 110px));
    height: calc(100vh - 106px);
    max-height: calc(100vh - 106px);
    display: none;
    transform: translateY(90px);
    box-shadow: 0 28px 70px rgba(18, 29, 35, .28);
  }
  body.preview-drawer-open .preview-panel { display: flex; }
}

@media (max-width: 1100px) {
  .app-navigation { width: 76px; flex-basis: 76px; padding-inline: 10px; }
  .nav-brand { justify-content: center; padding-inline: 0; }
  .nav-brand > div:last-child,
  .nav-link:not(.is-active) { font-size: 0; }
  .nav-link { justify-content: center; padding-inline: 8px; font-size: 0; }
  .nav-link .nav-symbol { font-size: 20px; }
  .nav-footer strong,
  .nav-footer small { display: none; }
  .app-main { width: calc(100% - 76px); }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-insights,
  .dashboard-details { grid-template-columns: 1fr; }
  .aging-strip { grid-template-columns: repeat(3, 1fr); }
  .management-view { grid-template-columns: 260px minmax(0, 1fr); }
  .settings-layout { grid-template-columns: 1fr; }
  .platform-access-columns { grid-template-columns: 1fr; }
  .settings-section:last-child { grid-column: auto; }
  .bank-transaction { grid-template-columns: minmax(180px, 1fr) minmax(120px, auto); }
  .bank-match-control,
  .bank-match-result,
  .bank-row-actions { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
  .app-navigation { position: fixed; inset: auto 0 0 0; z-index: 30; width: 100%; height: 64px; padding: 6px; }
  .nav-brand,
  .nav-footer { display: none; }
  .nav-links { grid-template-columns: repeat(7, 1fr); gap: 2px; margin: 0; }
  .nav-link,
  .nav-link:not(.is-active) { min-height: 50px; display: grid; place-items: center; gap: 0; padding: 2px; font-size: 0; }
  .app-main { width: 100%; padding-bottom: 64px; }
  .topbar { position: static; align-items: flex-start; padding: 12px; }
  .topbar-title h1 { font-size: 20px; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .button { min-height: 36px; padding-inline: 10px; font-size: 11px; }
  .autosave-indicator { display: none; }
  .dashboard-view,
  .banking-view,
  .reports-view,
  .settings-view { padding: 12px; }
  .dashboard-intro { align-items: flex-start; flex-direction: column; }
  .aging-strip { grid-template-columns: 1fr 1fr; }
  .workspace,
  body.invoice-sidebar-collapsed .workspace,
  body:not(.invoice-sidebar-collapsed) .workspace,
  body.invoice-sidebar-collapsed .workspace.is-empty { grid-template-columns: 1fr; padding: 10px; }
  .workspace .invoice-sidebar,
  body:not(.invoice-sidebar-collapsed) .workspace .invoice-sidebar { display: none; }
  .preview-panel {
    top: 0;
    right: 12px;
    bottom: auto;
    width: calc(100vw - 24px);
    height: calc(100vh - 88px);
    max-height: calc(100vh - 88px);
    transform: translateY(12px);
  }
  .management-view { grid-template-columns: 1fr; padding: 10px; }
  .management-sidebar { max-height: 420px; overflow: auto; }
  .report-grid { grid-template-columns: 1fr; }
  .report-wide { grid-column: auto; }
  .payment-entry { grid-template-columns: 1fr 1fr; }
  .payment-entry .button { min-height: 42px; }
  .document-actions { justify-content: flex-start; }
  .control-grid { grid-template-columns: 1fr; }
  .user-row { grid-template-columns: 1fr 130px; }
  .user-row .text-button { justify-self: start; }
  .cash-forecast,
  .bank-summary { grid-template-columns: 1fr 1fr; }
  .banking-toolbar { align-items: flex-start; flex-direction: column; }
  .banking-actions { justify-content: flex-start; }
  .notification-row { grid-template-columns: 1fr auto; }
  .notification-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 560px) {
  .topbar { flex-direction: column; }
  .topbar-actions { width: 100%; justify-content: flex-start; }
  .kpi-grid { grid-template-columns: 1fr; }
  .aging-strip { grid-template-columns: 1fr; }
  .aging-strip > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .aging-strip > div:last-child { border-bottom: 0; }
  .status-overview { grid-template-columns: 1fr; }
  .status-donut { margin: 0 auto; }
  .form-grid.two,
  .form-grid.three,
  .form-grid.four,
  .client-insights,
  .payment-entry { grid-template-columns: 1fr; }
  .field-span-two { grid-column: auto; }
  .preview-actions { align-items: stretch; }
  .preview-record-actions { width: 100%; }
  .preview-record-actions .button { flex: 1; }
  .extra-column-row { grid-template-columns: 24px minmax(100px, 1fr) 100px 30px 30px 30px; overflow-x: auto; }
  .user-row,
  .share-result { grid-template-columns: 1fr; }
  .operation-row { align-items: flex-start; }
  .cash-forecast,
  .bank-summary,
  .banking-filter,
  .guide-grid { grid-template-columns: 1fr; }
  .bank-summary article { border-right: 0; border-bottom: 1px solid var(--line); }
  .bank-summary article:last-child { border-bottom: 0; }
  .bank-transaction { grid-template-columns: 1fr; }
  .bank-transaction > b { text-align: left; }
}

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

@media print {
  html,
  body {
    width: 210mm !important;
    height: auto !important;
    min-height: 297mm !important;
    margin: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }

  .app-navigation,
  .topbar,
  .dashboard-view,
  .invoice-sidebar,
  .editor-panel,
  .preview-actions,
  .management-view,
  .banking-view,
  .reports-view,
  .settings-view,
  .toast-region { display: none !important; }

  .app-shell,
  .app-main,
  #invoiceView,
  .workspace,
  .preview-panel,
  .preview-stage {
    display: block !important;
    width: 210mm !important;
    height: auto !important;
    min-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
  }

  .preview-panel { position: static !important; max-height: none !important; }
  .invoice-preview {
    position: relative !important;
    inset: auto !important;
    width: 210mm !important;
    height: auto !important;
    min-height: 297mm !important;
    overflow: visible !important;
    transform: none !important;
    box-shadow: none !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .document-hero,
  .document-lines th,
  .document-summary .summary-total,
  .document-footer > div strong {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .document-hero { background: var(--blue) !important; box-shadow: inset 0 0 0 1000px var(--blue); }
  .document-lines thead { display: table-header-group; }
  .document-lines tr { break-inside: avoid; page-break-inside: avoid; }
  .document-lines th { background: var(--olive) !important; box-shadow: inset 0 0 0 1000px var(--olive); }
  .document-summary,
  .amount-words,
  .document-notes,
  .document-bottom,
  .integrity-seal,
  .document-footer { break-inside: avoid; page-break-inside: avoid; }
  .document-summary .summary-total { background: var(--olive) !important; box-shadow: inset 0 0 0 1000px var(--olive); }
  .document-footer { position: static !important; margin-top: 24px; }
}

@media screen {
  .editor-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .editor-step-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: #fff;
  }

  .editor-step-tabs {
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f5f7f9;
  }

  .editor-step-button {
    min-width: 0;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 0 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
  }

  .editor-step-button span {
    color: #87919c;
    font-size: 10px;
    font-weight: 900;
  }

  .editor-step-button.is-active {
    background: #fff;
    color: var(--blue-dark);
    box-shadow: 0 1px 4px rgba(24, 32, 43, .12);
  }

  .editor-step-button.is-active span { color: var(--blue); }
  .editor-step-button:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

  .editor-step-total {
    min-width: 125px;
    display: grid;
    gap: 1px;
    text-align: right;
  }

  .editor-step-total span { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
  .editor-step-total strong { font-size: 14px; overflow-wrap: anywhere; }

  .invoice-form {
    min-height: 0;
    max-height: none;
    flex: 1 1 auto;
    overscroll-behavior: contain;
  }

  .editor-step-footer {
    position: sticky;
    bottom: -16px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0 -16px -16px;
    padding: 10px 16px;
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,.97);
    backdrop-filter: blur(10px);
  }

  .editor-step-footer > span { color: var(--muted); font-size: 11px; font-weight: 800; }
  .editor-step-footer .button { min-height: 38px; }

  .mobile-preview-dock { display: none; }

  @media (min-width: 1451px) {
    .workspace,
    .workspace.is-list-collapsed,
    body.invoice-sidebar-collapsed .workspace,
    body:not(.invoice-sidebar-collapsed) .workspace {
      grid-template-columns: minmax(195px, 220px) minmax(0, 1fr) minmax(390px, min(31vw, 520px));
      align-items: start;
      gap: 12px;
      padding: 12px;
    }

    .workspace.is-list-collapsed,
    body.invoice-sidebar-collapsed .workspace {
      grid-template-columns: 52px minmax(0, 1fr) minmax(390px, min(31vw, 520px));
    }

    .workspace .invoice-sidebar-heading { justify-content: space-between; padding: 6px 6px 6px 12px; }
    .workspace .invoice-sidebar-heading strong,
    .workspace .invoice-sidebar-content { display: flex; }
    .workspace .invoice-sidebar-content { flex-direction: column; }

    .workspace.is-list-collapsed .invoice-sidebar-heading,
    body.invoice-sidebar-collapsed .workspace .invoice-sidebar-heading { justify-content: center; padding: 6px; }
    .workspace.is-list-collapsed .invoice-sidebar-heading strong,
    .workspace.is-list-collapsed .invoice-sidebar-content,
    body.invoice-sidebar-collapsed .workspace .invoice-sidebar-heading strong,
    body.invoice-sidebar-collapsed .workspace .invoice-sidebar-content { display: none; }

    .editor-panel { height: calc(100vh - 104px); max-height: calc(100vh - 104px); }
    .preview-panel {
      position: sticky;
      top: 12px;
      width: auto;
      height: calc(100vh - 104px);
      max-height: calc(100vh - 104px);
      display: flex;
      transform: none;
      box-shadow: 0 1px 0 rgba(24,32,43,.03);
    }

    .preview-toggle,
    .drawer-close { display: none !important; }
  }

  @media (min-width: 821px) and (max-width: 1450px) {
    .workspace,
    .workspace.is-list-collapsed,
    body.invoice-sidebar-collapsed .workspace,
    body:not(.invoice-sidebar-collapsed) .workspace {
      grid-template-columns: minmax(185px, 220px) minmax(0, 1fr);
      align-items: start;
      gap: 12px;
      padding: 12px 12px 120px;
    }

    .workspace.is-list-collapsed,
    body.invoice-sidebar-collapsed .workspace { grid-template-columns: 52px minmax(0, 1fr); }

    .workspace .invoice-sidebar-heading { justify-content: space-between; padding: 6px 6px 6px 12px; }
    .workspace .invoice-sidebar-heading strong,
    .workspace .invoice-sidebar-content { display: flex; }
    .workspace .invoice-sidebar-content { flex-direction: column; }

    .workspace.is-list-collapsed .invoice-sidebar-heading,
    body.invoice-sidebar-collapsed .workspace .invoice-sidebar-heading { justify-content: center; padding: 6px; }
    .workspace.is-list-collapsed .invoice-sidebar-heading strong,
    .workspace.is-list-collapsed .invoice-sidebar-content,
    body.invoice-sidebar-collapsed .workspace .invoice-sidebar-heading strong,
    body.invoice-sidebar-collapsed .workspace .invoice-sidebar-content { display: none; }

    .editor-panel { min-height: calc(100vh - 104px); }
    .invoice-form { max-height: none; overflow: visible; }
    .preview-toggle { display: inline-flex; }
    .drawer-close { display: grid; }
    .preview-panel {
      position: fixed;
      inset: 84px 16px 16px auto;
      z-index: 50;
      width: min(560px, calc(100vw - 32px));
      height: auto;
      max-height: none;
      display: none;
      transform: none;
      box-shadow: 0 28px 70px rgba(18, 29, 35, .28);
    }

    body.preview-drawer-open::before {
      position: fixed;
      z-index: 49;
      inset: 0;
      content: "";
      background: rgba(23, 36, 43, .38);
    }

    body.preview-drawer-open .preview-panel { display: flex; }
    .mobile-preview-dock {
      position: fixed;
      right: 20px;
      bottom: 18px;
      z-index: 28;
      width: min(340px, calc(100vw - 40px));
      min-height: 82px;
      display: grid;
      grid-template-columns: 56px minmax(0, 1fr) auto;
      align-items: center;
      gap: 12px;
      padding: 8px 12px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fff;
      color: var(--ink);
      text-align: left;
      box-shadow: 0 12px 36px rgba(23,36,43,.2);
    }

    body.preview-drawer-open .mobile-preview-dock { display: none; }
  }

  .mobile-invoice-thumbnail {
    position: relative;
    width: 56px;
    height: 79px;
    display: block;
    overflow: hidden;
    border: 1px solid var(--line);
    background: #fff;
    box-shadow: 0 2px 5px rgba(23,36,43,.12);
  }

  .mobile-invoice-thumbnail > .mobile-invoice-preview {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 794px !important;
    min-height: 1123px !important;
    height: auto !important;
    transform: scale(.07) !important;
    transform-origin: top left !important;
    box-shadow: none !important;
    pointer-events: none !important;
  }

  .mobile-preview-copy { min-width: 0; display: grid; gap: 4px; }
  .mobile-preview-copy strong,
  .mobile-preview-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-preview-copy strong { font-size: 12px; }
  .mobile-preview-copy span { color: var(--muted); font-size: 12px; font-weight: 800; }
  .mobile-preview-action { display: inline-flex; align-items: center; gap: 4px; color: var(--blue); font-size: 12px; font-weight: 900; white-space: nowrap; }
  .mobile-preview-action span { font-size: 22px; line-height: 1; }

  @media (max-width: 1100px) {
    .form-grid.four,
    .form-grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .line-editor {
      min-width: 0;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      align-items: end;
    }
    .line-order { grid-column: 1 / -1; display: flex; grid-template-rows: none; justify-content: flex-end; gap: 8px; }
    .line-description { grid-column: 1 / -1; }
    .line-editor .line-total { grid-column: 1; }
    .line-editor .line-remove { justify-self: end; }
    .line-editor.line-section,
    .line-editor.line-note { min-width: 0; grid-template-columns: minmax(0, 1fr) 38px; }
    .line-editor.line-section .line-order,
    .line-editor.line-note .line-order { grid-column: 1 / -1; }
    .line-editor.line-section .line-description,
    .line-editor.line-note .line-description { grid-column: 1; }
  }

  @media (max-width: 820px) {
    .workspace,
    .workspace.is-list-collapsed,
    body.invoice-sidebar-collapsed .workspace,
    body:not(.invoice-sidebar-collapsed) .workspace {
      grid-template-columns: minmax(0, 1fr);
      padding: 10px 10px 118px;
    }

    .workspace .invoice-sidebar { display: none !important; }
    .editor-panel { min-height: auto; height: auto; max-height: none; overflow: visible; }
    .invoice-form { min-height: 0; max-height: none; overflow: visible; padding: 12px; }
    .editor-step-nav { align-items: stretch; flex-direction: column; gap: 8px; padding: 9px; }
    .editor-step-tabs { width: 100%; }
    .editor-step-button { min-height: 42px; gap: 4px; padding: 0 4px; font-size: 11px; }
    .editor-step-total { display: flex; align-items: baseline; justify-content: space-between; text-align: left; }
    .editor-step-total strong { font-size: 13px; }
    .editor-step-footer { bottom: -12px; margin: 0 -12px -12px; padding: 9px 12px; }
    .editor-step-footer { position: static; margin-top: 2px; }

    .mobile-preview-dock {
      position: fixed;
      right: 12px;
      bottom: calc(72px + env(safe-area-inset-bottom));
      left: 12px;
      z-index: 29;
      min-height: 80px;
      display: grid;
      grid-template-columns: 56px minmax(0, 1fr) auto;
      align-items: center;
      gap: 11px;
      padding: 7px 11px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: rgba(255,255,255,.98);
      color: var(--ink);
      text-align: left;
      box-shadow: 0 12px 36px rgba(23,36,43,.2);
      backdrop-filter: blur(10px);
    }

    .preview-panel {
      position: fixed;
      inset: 10px 10px calc(74px + env(safe-area-inset-bottom));
      z-index: 50;
      width: auto;
      height: auto;
      max-height: none;
      display: none;
      transform: none;
      padding: 10px;
      box-shadow: 0 28px 70px rgba(18,29,35,.3);
    }

    .preview-actions { align-items: center; flex-wrap: nowrap; }
    .preview-record-actions { width: auto; }
    .preview-record-actions .button { flex: 0 0 auto; min-height: 36px; padding-inline: 9px; font-size: 11px; }
    .preview-stage { min-height: 0; overflow: auto; }
    body.preview-drawer-open .preview-panel { display: flex; }
    body.preview-drawer-open .mobile-preview-dock { display: none; }
    body.preview-drawer-open::before {
      position: fixed;
      z-index: 49;
      inset: 0;
      content: "";
      background: rgba(23, 36, 43, .46);
    }

    .document-actions { gap: 6px; }
    .document-actions .button { min-height: 38px; font-size: 12px; }
    .panel-heading { padding: 13px; }
  }

  @media (max-width: 560px) {
    .form-grid.two,
    .form-grid.three,
    .form-grid.four { grid-template-columns: minmax(0, 1fr); }
    .editor-step-button { flex-direction: column; gap: 0; font-size: 10px; }
    .editor-step-button span { font-size: 9px; }
    .mobile-preview-action { font-size: 11px; }
    .preview-actions { align-items: center; flex-wrap: wrap; gap: 6px; }
    .preview-zoom { min-height: 36px; gap: 2px; }
    .zoom-button { width: 28px; height: 28px; }
    .preview-zoom output { width: 34px; }
    .preview-record-actions { width: 100%; justify-content: space-between; gap: 5px; }
    .preview-record-actions .button { flex: 1 1 auto; padding-inline: 7px; font-size: 10px; }
    .preview-record-actions .drawer-close { flex: 0 0 36px; }
    .editor-step-footer .button { min-height: 40px; padding-inline: 10px; font-size: 12px; }
  }
}
