:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --sidebar: #0f1f2e;
  --sidebar-muted: #91a1b2;
  --sidebar-active: #1d4ed8;
  --text: #172033;
  --muted: #64748b;
  --soft: #94a3b8;
  --line: #dfe7f2;
  --line-strong: #cbd5e1;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --green: #047857;
  --green-soft: #ecfdf5;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --red: #b42318;
  --red-soft: #fef2f2;
  --button-font-weight: 400;
  --shadow: 0 14px 36px rgba(15, 31, 46, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Avenir Next", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon-sprite {
  display: none;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  padding: 24px 18px;
  overflow-y: auto;
  background: linear-gradient(180deg, #102538 0%, #0d1a28 100%);
  color: #ffffff;
}

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

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 10px;
  background: #ffffff;
  color: var(--sidebar);
  font-size: 18px;
  font-weight: 800;
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand strong {
  display: block;
  font-size: 18px;
  line-height: 1.15;
}

.brand small {
  display: block;
  margin-top: 3px;
  color: var(--sidebar-muted);
  font-size: 12px;
  font-weight: 600;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  height: 44px;
  align-items: center;
  gap: 11px;
  padding: 0 12px;
  border-radius: 10px;
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 700;
  transition: background 140ms ease, color 140ms ease;
}

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

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

.nav-item svg {
  width: 18px;
  height: 18px;
}

.user-panel {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}

.user-panel span {
  color: #bfdbfe;
  font-size: 11px;
  font-weight: 800;
}

.user-panel strong {
  min-width: 0;
  color: #ffffff;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.user-panel button {
  width: 100%;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  cursor: pointer;
  font-size: 12px;
  font-weight: var(--button-font-weight);
}

.user-panel button:hover {
  background: rgba(255, 255, 255, 0.14);
}

.workspace {
  min-width: 0;
  padding: 30px 34px 48px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
}

.page-header p,
.detail-title-row p {
  margin: 0 0 7px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.page-header h1,
.detail-title-row h1 {
  margin: 0;
  color: var(--text);
  font-size: 28px;
  line-height: 1.18;
  font-weight: 800;
}

.page-action-form {
  position: relative;
  margin: 0;
}

.page-action-button {
  display: inline-flex;
  height: 42px;
  align-items: center;
  gap: 9px;
  padding: 0 16px;
  border: 1px solid var(--blue);
  border-radius: 10px;
  background: var(--blue);
  color: #ffffff;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.2);
  cursor: pointer;
  font-size: 13px;
  font-weight: var(--button-font-weight);
}

.visually-hidden-file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.page-action-button:hover {
  background: #1d4ed8;
}

body.is-contract-importing .page-action-button {
  border-color: var(--line-strong);
  background: #eef2f7;
  color: var(--muted);
  box-shadow: none;
  cursor: wait;
  pointer-events: none;
}

.page-action-button svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.import-progress {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 2;
  width: min(280px, 72vw);
  gap: 8px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 14px 32px rgba(15, 31, 46, 0.12);
}

body.is-contract-importing .import-progress {
  display: grid;
}

.import-progress span {
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.import-progress div {
  position: relative;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}

.import-progress i {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -45%;
  width: 45%;
  border-radius: inherit;
  background: var(--blue);
  animation: import-progress-slide 1.15s ease-in-out infinite;
}

@keyframes import-progress-slide {
  0% {
    transform: translateX(0);
  }

  100% {
    transform: translateX(320%);
  }
}

.notice {
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid #fecaca;
  border-radius: 10px;
  background: var(--red-soft);
  color: var(--red);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.notice-success {
  border-color: #bbf7d0;
  background: var(--green-soft);
  color: var(--green);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  width: min(720px, calc(100vw - 48px));
  margin: 0;
  padding: 16px 18px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.45;
  box-shadow: 0 18px 42px rgba(15, 31, 46, 0.14);
  animation: toast-dismiss 240ms ease 3s forwards;
  pointer-events: none;
}

@keyframes toast-dismiss {
  to {
    opacity: 0;
    transform: translateY(8px);
    visibility: hidden;
  }
}

.proof-preview-modal[hidden] {
  display: none;
}

.proof-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
}

.proof-preview-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.48);
  cursor: pointer;
}

.proof-preview-dialog {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(960px, 100%);
  height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.22);
}

.proof-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.proof-preview-header h2 {
  margin: 0;
  color: var(--text);
  font-size: 17px;
  line-height: 1.3;
  font-weight: 800;
}

.proof-preview-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.proof-save-button,
.proof-close-button {
  display: inline-flex;
  height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: var(--button-font-weight);
}

.proof-save-button {
  padding: 0 13px;
}

.proof-close-button {
  width: 38px;
  padding: 0;
}

.proof-save-button:hover,
.proof-close-button:hover {
  border-color: var(--blue);
  background: #eff6ff;
  color: var(--blue);
}

.proof-save-button svg,
.proof-close-button svg {
  width: 16px;
  height: 16px;
}

.proof-preview-body {
  min-height: 0;
  background: #f8fafc;
}

.proof-preview-body iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

body.is-proof-preview-open {
  overflow: hidden;
}

.data-panel,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.filters {
  display: grid;
  grid-template-columns: minmax(260px, 1.4fr) minmax(150px, 0.55fr) minmax(150px, 0.55fr) minmax(150px, 0.55fr) 86px 82px;
  gap: 14px;
  align-items: end;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.search-field,
.filter-field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

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

.search-field div {
  display: flex;
  height: 40px;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #ffffff;
}

.search-field svg {
  color: var(--soft);
  flex: 0 0 auto;
}

.search-field input,
.filter-field input,
.filter-field select {
  width: 100%;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: 0;
  background: #ffffff;
  color: var(--text);
  font-size: 14px;
}

.search-field input {
  height: 38px;
  padding: 0;
  border: 0;
}

.filter-field input,
.filter-field select {
  padding: 0 11px;
}

.search-field div:focus-within,
.filter-field input:focus,
.filter-field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.filter-button,
.reset-link {
  display: grid;
  height: 40px;
  place-items: center;
  border-radius: 10px;
  font-size: 13px;
  font-weight: var(--button-font-weight);
}

.filter-button {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #ffffff;
  cursor: pointer;
}

.reset-link {
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--muted);
}

.table-shell {
  overflow-x: auto;
}

.crm-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: fixed;
}

.crm-table th:nth-child(1),
.crm-table td:nth-child(1) {
  width: 35%;
}

.crm-table th:nth-child(2),
.crm-table td:nth-child(2) {
  width: 18%;
}

.crm-table th:nth-child(3),
.crm-table td:nth-child(3) {
  width: 13%;
}

.crm-table th:nth-child(4),
.crm-table td:nth-child(4) {
  width: 16%;
}

.crm-table th:nth-child(5),
.crm-table td:nth-child(5) {
  width: 18%;
}

.crm-table.is-clients th:nth-child(1),
.crm-table.is-clients td:nth-child(1) {
  width: 28%;
}

.crm-table.is-clients th:nth-child(2),
.crm-table.is-clients td:nth-child(2) {
  width: 20%;
}

.crm-table.is-clients th:nth-child(3),
.crm-table.is-clients td:nth-child(3) {
  width: 13%;
}

.crm-table.is-clients th:nth-child(4),
.crm-table.is-clients td:nth-child(4) {
  width: 12%;
}

.crm-table.is-clients th:nth-child(5),
.crm-table.is-clients td:nth-child(5) {
  width: 17%;
}

.crm-table.is-clients th:nth-child(6),
.crm-table.is-clients td:nth-child(6) {
  width: 10%;
}

.crm-table.is-contracts th:nth-child(1),
.crm-table.is-contracts td:nth-child(1) {
  width: 24%;
}

.crm-table.is-contracts th:nth-child(2),
.crm-table.is-contracts td:nth-child(2) {
  width: 12%;
}

.crm-table.is-contracts th:nth-child(3),
.crm-table.is-contracts td:nth-child(3) {
  width: 17%;
}

.crm-table.is-contracts th:nth-child(4),
.crm-table.is-contracts td:nth-child(4) {
  width: 14%;
}

.crm-table.is-contracts th:nth-child(5),
.crm-table.is-contracts td:nth-child(5) {
  width: 11%;
}

.crm-table.is-contracts th:nth-child(6),
.crm-table.is-contracts td:nth-child(6) {
  width: 11%;
}

.crm-table.is-contracts th:nth-child(7),
.crm-table.is-contracts td:nth-child(7) {
  width: 11%;
}

.crm-table.is-invoices th:nth-child(1),
.crm-table.is-invoices td:nth-child(1) {
  width: 15%;
}

.crm-table.is-invoices th:nth-child(2),
.crm-table.is-invoices td:nth-child(2) {
  width: 17%;
}

.crm-table.is-invoices th:nth-child(3),
.crm-table.is-invoices td:nth-child(3) {
  width: 25%;
}

.crm-table.is-invoices th:nth-child(4),
.crm-table.is-invoices td:nth-child(4) {
  width: 11%;
}

.crm-table.is-invoices th:nth-child(5),
.crm-table.is-invoices td:nth-child(5) {
  width: 16%;
}

.crm-table.is-invoices th:nth-child(6),
.crm-table.is-invoices td:nth-child(6) {
  width: 10%;
}

.crm-table.is-invoices th:nth-child(7),
.crm-table.is-invoices td:nth-child(7) {
  width: 14%;
}

.crm-table.is-payments th:nth-child(1),
.crm-table.is-payments td:nth-child(1) {
  width: 14%;
}

.crm-table.is-payments th:nth-child(2),
.crm-table.is-payments td:nth-child(2) {
  width: 10%;
}

.crm-table.is-payments th:nth-child(3),
.crm-table.is-payments td:nth-child(3) {
  width: 15%;
}

.crm-table.is-payments th:nth-child(4),
.crm-table.is-payments td:nth-child(4) {
  width: 14%;
}

.crm-table.is-payments th:nth-child(5),
.crm-table.is-payments td:nth-child(5) {
  width: 29%;
}

.crm-table.is-payments th:nth-child(6),
.crm-table.is-payments td:nth-child(6) {
  width: 12%;
}

.crm-table.is-payments th:nth-child(7),
.crm-table.is-payments td:nth-child(7) {
  width: 6%;
}

.crm-table.is-contract-invoices th:nth-child(1),
.crm-table.is-contract-invoices td:nth-child(1) {
  width: 17%;
}

.crm-table.is-contract-invoices th:nth-child(2),
.crm-table.is-contract-invoices td:nth-child(2) {
  width: 31%;
}

.crm-table.is-contract-invoices th:nth-child(3),
.crm-table.is-contract-invoices td:nth-child(3) {
  width: 13%;
}

.crm-table.is-contract-invoices th:nth-child(4),
.crm-table.is-contract-invoices td:nth-child(4) {
  width: 17%;
}

.crm-table.is-contract-invoices th:nth-child(5),
.crm-table.is-contract-invoices td:nth-child(5) {
  width: 11%;
}

.crm-table.is-contract-invoices th:nth-child(6),
.crm-table.is-contract-invoices td:nth-child(6) {
  width: 11%;
}

.crm-table thead {
  background: #f8fafc;
}

.crm-table th {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: left;
  text-transform: uppercase;
}

.crm-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  color: #475569;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 400;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

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

.clickable-row {
  cursor: pointer;
  transition: background 120ms ease;
}

.clickable-row:hover,
.clickable-row:focus {
  background: #f8fbff;
  outline: none;
}

.table-inline-link {
  color: var(--blue);
  font-weight: 500;
}

.table-inline-link:hover {
  text-decoration: underline;
}

.proof-cell {
  text-align: center;
}

.proof-preview-link {
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #ffffff;
  color: var(--muted);
}

.proof-preview-link:hover {
  border-color: var(--blue);
  background: #eff6ff;
  color: var(--blue);
}

.proof-preview-link svg {
  width: 17px;
  height: 17px;
}

.proof-empty {
  color: var(--muted);
  font-weight: 700;
}

.primary-cell a {
  display: grid;
  gap: 3px;
}

.row-kicker {
  color: var(--soft);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.primary-cell .row-title {
  display: block;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.primary-cell small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.amount-cell {
  color: var(--text) !important;
  font-weight: 500;
}

.status-chip {
  display: inline-grid;
  min-height: 26px;
  place-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-pending,
.status-pending-review,
.status-needs-fix,
.status-draft {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-rejected,
.status-failed,
.status-cancelled,
.status-refunded,
.status-revoked {
  background: var(--red-soft);
  color: var(--red);
}

.status-archived {
  background: #eef2f7;
  color: #64748b;
}

.status-admin {
  background: #eef2ff;
  color: var(--blue);
}

.status-staff {
  background: #eef2f7;
  color: #475569;
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.row-meta span {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475569;
  font-size: 11px;
  font-weight: 500;
}

.row-meta svg {
  width: 15px;
  height: 15px;
  margin-left: auto;
  color: var(--soft);
}

.empty-state {
  height: 112px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}

.detail-header {
  margin-bottom: 20px;
}

.detail-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.back-link:hover,
.return-button:hover {
  color: var(--blue);
}

.return-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
  font-weight: var(--button-font-weight);
  box-shadow: 0 8px 22px rgba(15, 31, 46, 0.06);
}

.return-button svg {
  width: 16px;
  height: 16px;
}

.detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.detail-title-row span:not(.status-chip) {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.detail-panel {
  padding: 22px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.detail-field {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdff;
}

.detail-field span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-field strong {
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.client-form,
.related-panel {
  margin-top: 18px;
}

.client-editor,
.related-panel,
.obligations-editor,
.invoice-schedule-editor,
.invoice-download-panel,
.terms-editor {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.editor-heading,
.related-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.editor-heading h2,
.related-heading h2 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  line-height: 1.25;
  font-weight: 800;
}

.editor-title-block {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.source-file-link {
  display: inline-flex;
  max-width: min(520px, 48vw);
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
  font-weight: var(--button-font-weight);
}

.source-file-link:hover {
  color: var(--blue);
}

.source-file-link svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.source-file-link span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-heading p,
.related-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.button-group {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.save-button {
  min-width: 92px;
  height: 40px;
  border: 1px solid var(--blue);
  border-radius: 10px;
  background: var(--blue);
  color: #ffffff;
  font-weight: var(--button-font-weight);
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.2);
}

.save-generate-button {
  min-width: 148px;
}

.save-button:hover {
  background: #1d4ed8;
}

.save-button:disabled,
.save-button[aria-disabled="true"] {
  border-color: var(--line-strong);
  background: #eef2f7;
  color: var(--muted);
  cursor: not-allowed;
  box-shadow: none;
}

.save-button.secondary-action {
  border-color: var(--line-strong);
  background: #ffffff;
  color: var(--text);
  box-shadow: none;
}

.save-button.secondary-action:disabled,
.save-button.secondary-action[aria-disabled="true"] {
  border-color: var(--line-strong);
  background: #eef2f7;
  color: var(--muted);
}

.save-button.secondary-action:hover:not(:disabled) {
  border-color: var(--blue);
  color: var(--blue);
  background: #eff6ff;
}

.item-action-group {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.add-item-button,
.apply-items-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  font-size: 14px;
  font-weight: var(--button-font-weight);
  cursor: pointer;
}

.add-item-button:hover,
.apply-items-button:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: #eff6ff;
}

.add-item-button svg,
.apply-items-button svg {
  width: 17px;
  height: 17px;
}

.apply-items-button {
  border-color: rgba(37, 99, 235, 0.28);
  background: #eff6ff;
  color: var(--blue);
}

.add-item-button:disabled,
.apply-items-button:disabled,
.add-item-button[aria-disabled="true"],
.apply-items-button[aria-disabled="true"] {
  border-color: var(--line-strong);
  background: #eef2f7;
  color: var(--muted);
  cursor: not-allowed;
}

.invoice-download-panel {
  margin-top: 18px;
}

.invoice-download-list {
  display: grid;
  gap: 10px;
  padding: 16px 20px;
}

.invoice-download-link {
  display: inline-flex;
  max-width: min(680px, 100%);
  min-width: 0;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.3;
  font-weight: var(--button-font-weight);
}

.invoice-download-link:hover {
  color: var(--blue);
}

.invoice-download-link svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.invoice-download-link span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.payment-injection-panel {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.payment-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 18px 20px 20px;
}

.payment-invoice-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  border-bottom: 1px solid var(--line);
  background: var(--line);
}

.payment-invoice-summary div {
  display: grid;
  gap: 6px;
  min-height: 86px;
  align-content: center;
  padding: 16px 20px;
  background: #ffffff;
}

.payment-invoice-summary span,
.payment-invoice-items-head span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.payment-invoice-summary strong {
  color: var(--text);
  font-size: 16px;
  line-height: 1.35;
  font-weight: 500;
}

.payment-invoice-items {
  display: grid;
}

.payment-invoice-items-head,
.payment-invoice-item-row {
  display: grid;
  grid-template-columns: minmax(260px, 1.5fr) minmax(180px, 0.8fr) minmax(140px, 0.6fr);
  gap: 16px;
  align-items: center;
  padding: 13px 20px;
  border-bottom: 1px solid var(--line);
}

.payment-invoice-items-head {
  background: #f8fafc;
}

.payment-invoice-item-row span {
  color: #475569;
  font-size: 14px;
  line-height: 1.4;
}

.payment-save-form {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(190px, 0.9fr) minmax(220px, 0.9fr) minmax(150px, 180px);
  gap: 12px;
  align-items: end;
  justify-content: stretch;
  padding: 18px 20px 20px;
}

.payment-save-form .save-button {
  width: 100%;
  height: 42px;
}

.payment-receipt-field {
  position: relative;
}

.payment-receipt-button {
  display: inline-flex;
  width: 100%;
  height: 42px;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: var(--button-font-weight);
}

.payment-receipt-button:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: #eff6ff;
}

.payment-receipt-button svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.payment-receipt-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: none;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 20px;
}

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

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

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

.detail-form-contracts .terms-grid {
  grid-template-columns: 1fr;
}

.form-field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

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

.form-field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: 0;
  background: #ffffff;
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

.form-field input,
.form-field select {
  height: 42px;
  padding: 0 12px;
}

.form-field textarea {
  min-height: 104px;
  padding: 11px 12px;
  resize: vertical;
}

.form-field input[readonly] {
  background: #f8fafc;
  color: var(--muted);
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.contract-list {
  display: grid;
}

.obligations-editor,
.terms-editor {
  margin-top: 18px;
}

.obligation-list {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.invoice-item-list {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.obligation-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(150px, 0.8fr) minmax(150px, 0.8fr) minmax(140px, 0.7fr) minmax(120px, 0.6fr);
  gap: 14px;
  align-items: end;
}

.invoice-item-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) repeat(4, minmax(120px, 0.75fr)) repeat(2, minmax(140px, 0.8fr));
  gap: 14px;
  align-items: end;
}

.invoice-item-row.is-new {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.contract-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  transition: background 120ms ease;
}

.contract-row:last-child {
  border-bottom: 0;
}

.contract-row:hover,
.contract-row:focus {
  background: #f8fbff;
  outline: none;
}

.contract-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.contract-main strong {
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.contract-main small {
  color: var(--muted);
  font-size: 13px;
}

.contract-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.contract-meta > span:not(.status-chip) {
  min-height: 26px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef2f7;
}

.contract-meta svg {
  width: 16px;
  height: 16px;
  color: var(--soft);
}

.empty-related {
  padding: 28px 20px;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.settings-card {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-card span {
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.settings-card h2 {
  margin: 10px 0 8px;
  color: var(--text);
  font-size: 18px;
}

.settings-card p {
  min-height: 48px;
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
}

.settings-card strong {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--blue);
  font-size: 12px;
}

.staff-permissions-panel {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.staff-grant-form {
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(180px, 260px) 124px 112px;
  gap: 14px;
  align-items: end;
  justify-content: start;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.staff-grant-form .save-button {
  width: 112px;
}

.staff-table {
  min-width: 760px;
}

.staff-table th:nth-child(1),
.staff-table td:nth-child(1) {
  width: 34%;
}

.staff-table th:nth-child(2),
.staff-table td:nth-child(2) {
  width: 22%;
}

.staff-table th:nth-child(3),
.staff-table td:nth-child(3),
.staff-table th:nth-child(4),
.staff-table td:nth-child(4) {
  width: 12%;
}

.staff-table th:nth-child(5),
.staff-table td:nth-child(5) {
  width: 20%;
}

.table-action-button {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  cursor: pointer;
  font-size: 12px;
  font-weight: var(--button-font-weight);
}

.table-action-button:hover {
  border-color: #fca5a5;
  background: #fee2e2;
}

.muted-action,
.settings-readonly {
  color: var(--muted);
  font-weight: 700;
}

.settings-readonly {
  padding: 24px 20px;
}

.staff-detail-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.staff-detail-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(220px, 0.55fr) minmax(140px, 0.3fr) 112px;
  gap: 14px;
  align-items: end;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.staff-detail-actions {
  align-self: end;
}

.staff-detail-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.staff-detail-meta div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdff;
}

.staff-detail-meta span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.staff-detail-meta strong {
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.staff-revoke-form {
  padding: 18px 20px;
}

.login-page {
  min-height: 100vh;
  background: radial-gradient(circle at top left, #dbeafe 0, rgba(219, 234, 254, 0) 36%), var(--bg);
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
}

.login-panel {
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 24px;
  color: var(--text);
}

.login-panel h1 {
  margin: 0;
  color: var(--text);
  font-size: 28px;
  line-height: 1.2;
}

.login-panel p {
  margin: 10px 0 20px;
  color: var(--muted);
  line-height: 1.5;
}

.google-login-button {
  display: inline-flex;
  width: 100%;
  height: 44px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 22px rgba(15, 31, 46, 0.06);
}

.google-login-button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.google-login-button span {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  background: var(--blue);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
}

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

  .filters {
    grid-template-columns: minmax(220px, 1fr) minmax(140px, 0.6fr) minmax(140px, 0.6fr);
  }

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

  .invoice-item-row {
    grid-template-columns: minmax(220px, 1fr) repeat(2, minmax(120px, 0.6fr));
  }

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

  .staff-grant-form {
    grid-template-columns: minmax(240px, 360px) minmax(170px, 240px) 120px 108px;
  }

  .staff-detail-form,
  .staff-detail-meta {
    grid-template-columns: 1fr;
  }

  .payment-picker-grid,
  .payment-invoice-summary {
    grid-template-columns: 1fr;
  }

  .payment-save-form {
    grid-template-columns: minmax(150px, 0.8fr) minmax(160px, 0.9fr) minmax(200px, 1fr) minmax(140px, 160px);
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    min-height: auto;
    padding: 18px;
  }

  .user-panel {
    margin-top: 18px;
  }

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

  .workspace {
    padding: 22px 16px 36px;
  }

  .filters,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .page-header,
  .detail-title-row {
    display: grid;
    gap: 14px;
  }

  .detail-nav-row,
  .editor-heading,
  .related-heading,
  .contract-row {
    display: grid;
  }

  .return-button,
  .save-button,
  .add-item-button,
  .apply-items-button,
  .page-action-button {
    width: 100%;
    justify-content: center;
  }

  .page-action-form {
    width: 100%;
  }

  .form-grid {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .button-group,
  .obligation-row,
  .invoice-item-row,
  .payment-invoice-items-head,
  .payment-invoice-item-row {
    grid-template-columns: 1fr;
  }

  .button-group {
    display: grid;
    justify-content: stretch;
  }

  .staff-grant-form {
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  .staff-grant-form .save-button {
    width: 100%;
  }

  .payment-save-form {
    grid-template-columns: 1fr;
  }

  .contract-meta {
    justify-content: flex-start;
  }

  .crm-table {
    min-width: 860px;
  }
}
