:root {
  color-scheme: light;
  --deep-blue: #000548;
  --navy-blue: #222867;
  --brand-blue: #21409a;
  --wine: #5e0e3a;
  --wine-mid: #791e4e;
  --wine-light: #942c61;
  --cool-gray: #bebebe;
  --light-gray: #dddddd;
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-soft: #f9f9fb;
  --line: #dddddd;
  --line-strong: #bebebe;
  --text: #000548;
  --muted: #5e668c;
  --accent: #222867;
  --accent-dark: #000548;
  --accent-soft: #eef1fb;
  --warn: #a16207;
  --danger: #5e0e3a;
  --shadow: 0 10px 26px rgba(0, 5, 72, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.auth-screen {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 32px 20px;
  background: #ffffff;
}

.auth-screen.hidden {
  display: none;
}

.auth-shell {
  display: grid;
  width: min(360px, 100%);
  gap: 28px;
}

.auth-logo {
  display: block;
  width: min(270px, 80vw);
  height: auto;
}

.auth-heading {
  display: grid;
  gap: 5px;
}

.auth-heading p,
.auth-heading h1 {
  margin: 0;
}

.auth-heading h1 {
  color: var(--deep-blue);
  font-size: 28px;
  font-weight: 400;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.4;
}

.auth-error.hidden {
  display: block;
  visibility: hidden;
}

.auth-submit {
  width: 100%;
  min-height: 42px;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 18px;
  background: var(--deep-blue);
  color: #ffffff;
}

.brand {
  display: grid;
  gap: 10px;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3 {
  margin: 0;
}

.brand-logo {
  display: block;
  width: min(158px, 100%);
  height: auto;
}

.brand p {
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  line-height: 1.35;
}

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

.nav-item {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 11px 12px;
  background: transparent;
  color: rgba(255, 255, 255, 0.74);
  text-align: left;
  font-weight: 400;
}

.nav-item:hover,
.nav-item.active {
  border-color: rgba(255, 255, 255, 0.2);
  background: var(--navy-blue);
  color: #ffffff;
}

.connection-card {
  display: grid;
  gap: 12px;
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  width: fit-content;
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
}

.status-pill.connected {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

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

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

.eyebrow {
  color: var(--wine);
  font-size: 12px;
  font-weight: 400;
}

.topbar h2 {
  margin-top: 4px;
  font-size: 28px;
  font-weight: 400;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  font-weight: 400;
}

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

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

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

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.sidebar .secondary-button {
  background: #ffffff;
  color: var(--deep-blue);
}

.ghost-button {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.topbar .ghost-button {
  background: #ffffff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.dashboard-context-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
  padding: 2px 2px 14px;
}

.dashboard-today {
  display: grid;
  gap: 3px;
}

.dashboard-today > span,
.dashboard-user-card span,
.dashboard-block-header span,
.dashboard-stat span,
.dashboard-operation-stat span {
  color: var(--muted);
  font-size: 11px;
}

.dashboard-today strong {
  color: var(--deep-blue);
  font-size: 22px;
  font-weight: 500;
}

.dashboard-today small,
.dashboard-user-card small,
.dashboard-stat small,
.dashboard-operation-stat small,
.dashboard-block-header > small {
  color: var(--muted);
  font-size: 11px;
}

.dashboard-user-card {
  display: flex;
  align-items: center;
  min-width: 280px;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 9px 12px;
}

.dashboard-user-card > div {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.dashboard-user-card strong,
.dashboard-user-card small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-user-card strong {
  color: var(--deep-blue);
  font-size: 13px;
  font-weight: 600;
}

.dashboard-user-avatar {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: var(--navy-blue);
  color: #ffffff !important;
  font-size: 12px !important;
  font-weight: 600;
}

.dashboard-block {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.dashboard-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 54px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  padding: 10px 16px;
}

.dashboard-block-header > div {
  display: grid;
  gap: 3px;
}

.dashboard-block-header h3 {
  margin: 0;
  color: var(--deep-blue);
  font-size: 15px;
  font-weight: 500;
}

.dashboard-block-header > small {
  text-align: right;
}

.dashboard-block-header > small.dashboard-status-warning {
  color: var(--wine);
}

.dashboard-finance-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.dashboard-stat {
  display: grid;
  min-width: 0;
  gap: 5px;
  border-right: 1px solid var(--line);
  padding: 17px 18px;
}

.dashboard-stat:last-child {
  border-right: 0;
}

.dashboard-stat strong {
  overflow-wrap: anywhere;
  color: var(--deep-blue);
  font-size: 24px;
  font-weight: 500;
}

.dashboard-stat-result {
  background: #fbf7f9;
}

.dashboard-stat-result strong {
  color: var(--wine);
}

.dashboard-lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr);
  gap: 14px;
  margin-top: 14px;
}

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

.dashboard-operation-stat {
  display: grid;
  min-width: 0;
  gap: 5px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 15px 16px;
}

.dashboard-operation-stat:nth-child(2) {
  border-right: 0;
}

.dashboard-operation-stat strong {
  overflow-wrap: anywhere;
  color: var(--deep-blue);
  font-size: 22px;
  font-weight: 500;
}

.dashboard-operation-wide {
  grid-column: 1 / -1;
  border-right: 0;
  border-bottom: 0;
}

.dashboard-operation-wide strong {
  font-size: 16px;
}

.dashboard-kyc-table-wrap {
  max-height: 250px;
}

.dashboard-kyc-table th,
.dashboard-kyc-table td {
  padding-top: 8px;
  padding-bottom: 8px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  font-size: 26px;
  font-weight: 400;
  color: var(--deep-blue);
}

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

.content-grid.two {
  grid-template-columns: minmax(0, 1.55fr) minmax(360px, 0.9fr);
}

.content-grid.two.companies-grid {
  grid-template-columns: minmax(0, 1.25fr) minmax(460px, 1fr);
}

.content-grid.stacked-data-grid {
  grid-template-columns: 1fr;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  background: var(--surface-soft);
}

.panel h3 {
  font-size: 16px;
  font-weight: 400;
}

.search-input {
  width: min(260px, 45%);
}

.panel-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.panel-tools .search-input {
  width: 240px;
}

.report-catalog-group {
  padding: 16px;
}

.report-catalog-group h4 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.report-catalog-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 320px));
  gap: 10px;
}

.report-launch-button {
  display: grid;
  gap: 5px;
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px 14px;
  color: var(--text);
  text-align: left;
}

.report-launch-button:hover {
  border-color: var(--brand-blue);
  background: var(--accent-soft);
}

.report-launch-button span {
  color: var(--muted);
  font-size: 11px;
}

.report-launch-button strong {
  color: var(--deep-blue);
  font-size: 15px;
  font-weight: 500;
}

.table-wrap {
  overflow: auto;
}

#companiesView .table-wrap,
#contactsView .table-wrap,
#coverNotesView .table-wrap,
#serviceAgreementsView .service-agreements-table-wrap,
#paymentsView .payments-table-wrap {
  max-height: clamp(430px, calc(100dvh - 230px), 780px);
  overflow: auto;
}

.service-agreements-table {
  min-width: 1180px;
}

#paymentsView .form-grid {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

#paymentsView textarea[name="notes"] {
  height: 38px;
  min-height: 38px;
}

.payment-allocation-editor {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 2px 0 0;
  padding: 12px;
  background: var(--surface-soft);
}

.payment-allocation-editor.hidden {
  display: none;
}

.payment-allocation-editor legend {
  padding: 0 6px;
  color: var(--brand-blue);
  font-size: 12px;
  font-weight: 600;
}

.payment-table {
  min-width: 1120px;
}

.payment-filter-bar,
.cover-note-filter-bar {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.filter-heading {
  align-self: center;
  margin-right: 4px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.filter-result {
  align-self: center;
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.filter-result.error {
  color: var(--wine);
}

.segmented-control {
  display: inline-flex;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented-control button {
  border: 0;
  border-right: 1px solid var(--line);
  padding: 7px 11px;
  background: #ffffff;
  color: var(--muted);
}

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

.segmented-control button.active {
  background: var(--navy-blue);
  color: #ffffff;
}

.compact-filter {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.compact-filter select,
.compact-filter input {
  width: 145px;
  height: 36px;
  min-height: 36px;
  padding: 6px 9px;
}

.compact-filter-reset {
  min-height: 36px;
}

.allocation-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef1f6;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.allocation-status.partial {
  background: #fff4d8;
  color: #735312;
}

.allocation-status.allocated {
  background: #e8f4ed;
  color: #24613d;
}

.allocation-list {
  display: grid;
  gap: 4px;
  min-width: 190px;
}

.allocation-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.allocation-line .table-button {
  flex: 0 0 auto;
}

.balance-overdue {
  color: var(--wine);
}

.balance-settled {
  color: var(--muted);
}

.import-preview-wrap {
  max-height: 420px;
}

.import-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 12px 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-soft);
  color: var(--brand-blue);
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
}

.split-table .group-heading th {
  top: 0;
  z-index: 4;
  border-bottom: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--deep-blue);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0;
}

.split-table .column-heading th {
  top: 39px;
  z-index: 3;
}

.cover-placement-table {
  min-width: 1180px;
}

.cover-placement-table th,
.cover-placement-table td {
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.18;
}

.cover-placement-table .column-heading th {
  top: 30px;
}

.cover-placement-table th {
  font-size: 11px;
}

.cover-placement-table .muted {
  margin-top: 1px;
  font-size: 10.5px;
  line-height: 1.15;
}

.cover-placement-table .link-button {
  font-size: 12px;
  line-height: 1.15;
}

.cover-placement-table .group-heading th {
  padding-top: 8px;
  padding-bottom: 8px;
  font-size: 10.5px;
}

.compact-data-table th,
.compact-data-table td {
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.18;
}

.compact-data-table th {
  font-size: 11px;
}

.compact-data-table .muted {
  margin-top: 1px;
  font-size: 10.5px;
  line-height: 1.15;
}

.compact-data-table .link-button {
  font-size: 12px;
  line-height: 1.15;
}

.compact-data-table .badge {
  min-height: 20px;
  padding: 2px 7px;
  font-size: 10.5px;
}

.compact-data-table .table-button {
  min-height: 24px;
  padding: 3px 7px;
  font-size: 11px;
}

.compact-data-table .row-actions {
  gap: 5px;
}

.table-input,
.table-select {
  width: 100%;
  min-width: 120px;
  min-height: 30px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
}

.table-input:disabled,
.table-select:disabled {
  background: #f5f6f9;
  color: var(--muted);
}

.placement-start {
  border-left: 2px solid var(--line-strong);
}

.cover-note-group-start td {
  border-top: 2px solid #e7eaf4;
}

.cover-note-cell {
  min-width: 150px;
}

tbody tr:hover {
  background: #fafafd;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 4px 9px;
  background: #f3f3f5;
  color: var(--deep-blue);
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
}

.badge.ok {
  background: #eef1fb;
  color: var(--brand-blue);
}

.badge.warn {
  background: #fef3c7;
  color: var(--warn);
}

.badge.bad {
  background: #f7e9f0;
  color: var(--wine);
}

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

#companiesView .form-grid,
#contactsView .form-grid,
#coverNotesView .form-grid,
#serviceAgreementsView .form-grid {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

#serviceAgreementForm textarea[name="short_description"],
#serviceAgreementForm textarea[name="payment_terms"],
#serviceAgreementForm textarea[name="notes"],
#serviceEndorsementForm textarea {
  height: 38px;
  min-height: 38px;
}

.detail-form {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.project-page {
  display: grid;
  gap: 14px;
}

.project-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
}

.project-header h3 {
  margin: 2px 0 4px;
  font-size: 24px;
  font-weight: 500;
}

.project-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.project-payment-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.project-payment-summary > div {
  display: grid;
  min-width: 0;
  gap: 4px;
  padding: 12px 16px;
  border-right: 1px solid var(--line);
}

.project-payment-summary > div:last-child {
  border-right: 0;
}

.project-payment-summary span,
.project-payment-summary small {
  color: var(--muted);
  font-size: 12px;
}

.project-payment-summary strong {
  overflow-wrap: anywhere;
  color: var(--deep-blue);
  font-size: 18px;
  font-weight: 500;
}

.project-payment-summary strong.balance-overdue {
  color: var(--wine);
}

.project-payment-summary strong.balance-settled {
  color: var(--muted);
}

.panel-subheader {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  padding: 10px 16px;
}

.panel-subheader h4 {
  margin: 0;
  color: var(--brand-blue);
  font-size: 13px;
  font-weight: 600;
}

.report-dialog {
  width: min(1500px, calc(100vw - 28px));
  height: min(920px, calc(100dvh - 28px));
  max-width: none;
  max-height: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 22px 70px rgba(12, 18, 16, 0.28);
}

.report-dialog::backdrop {
  background: rgba(12, 18, 16, 0.48);
}

.report-dialog-shell {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

.report-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  padding: 13px 16px;
}

.report-dialog-header h3 {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 500;
}

.report-filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
}

.report-filter-grid input,
.report-filter-grid select {
  min-height: 36px;
  padding: 7px 9px;
}

.accrual-period-presets {
  display: flex;
  align-items: end;
  gap: 18px;
}

.period-preset-group {
  display: grid;
  gap: 5px;
}

.period-preset-group > span {
  color: var(--muted);
  font-size: 11px;
}

.accrual-period-presets .segmented-control {
  min-height: 32px;
  border-radius: 6px;
}

.accrual-period-presets .segmented-control button {
  min-width: 44px;
  padding: 5px 10px;
  font-size: 12px;
}

.report-filter-actions {
  display: flex;
  grid-column: 1 / -1;
  justify-content: flex-end;
  gap: 10px;
}

.report-summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.report-summary-strip > div {
  display: grid;
  gap: 3px;
  min-width: 0;
  border-right: 1px solid var(--line);
  padding: 9px 16px;
}

.report-summary-strip > div:last-child {
  border-right: 0;
}

.report-summary-strip span {
  color: var(--muted);
  font-size: 11px;
}

.report-summary-strip strong {
  color: var(--deep-blue);
  font-size: 17px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.report-output {
  min-height: 0;
  overflow: auto;
  background: #ffffff;
}

.report-output-section + .report-output-section {
  border-top: 1px solid var(--line);
}

.report-output-heading {
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  padding: 9px 16px;
}

.report-output-heading h4 {
  margin: 0;
  color: var(--brand-blue);
  font-size: 13px;
  font-weight: 500;
}

.report-totals-table {
  min-width: 1080px;
}

.accrual-breakdown-table {
  min-width: 720px;
}

.reconciliation-totals-table {
  min-width: 1380px;
}

.reconciliation-operations-table,
.reconciliation-documents-table {
  min-width: 1320px;
}

.report-rate-error {
  color: var(--wine);
}

.report-detail-table {
  min-width: 1420px;
}

.management-summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.management-summary-strip > div {
  display: grid;
  gap: 3px;
  min-width: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 9px 16px;
}

.management-summary-strip > div:nth-child(4n) {
  border-right: 0;
}

.management-summary-strip > div:nth-last-child(-n + 4) {
  border-bottom: 0;
}

.management-summary-strip span {
  color: var(--muted);
  font-size: 11px;
}

.management-summary-strip strong {
  color: var(--deep-blue);
  font-size: 17px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.management-summary-strip small {
  color: var(--muted);
  font-size: 10px;
}

.management-output-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.management-chart-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 7px 14px;
}

.management-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.management-legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--legend-color);
}

.management-legend-line {
  width: 14px;
  height: 2px;
  background: var(--legend-color);
}

.management-trend-chart {
  min-height: 290px;
  overflow-x: auto;
  padding: 12px 16px 6px;
}

.management-trend-chart svg {
  display: block;
  width: 100%;
  min-width: 760px;
  height: auto;
}

.management-chart-grid-line {
  stroke: #e6e7ec;
  stroke-width: 1;
}

.management-chart-zero-line {
  stroke: #9ca2ba;
  stroke-width: 1.25;
}

.management-chart-axis-label,
.management-chart-period-label {
  fill: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 10px;
  letter-spacing: 0;
}

.management-chart-net-line {
  fill: none;
  stroke: var(--deep-blue);
  stroke-width: 2.5;
}

.management-chart-net-point {
  fill: #ffffff;
  stroke: var(--deep-blue);
  stroke-width: 2;
}

.management-analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
}

.management-analysis-grid > section + section {
  border-left: 1px solid var(--line);
}

.management-ranked-chart {
  display: grid;
  gap: 10px;
  min-height: 220px;
  padding: 14px 16px 16px;
}

.management-counterparty-chart {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 24px;
}

.management-ranked-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(140px, 1.2fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.management-ranked-label {
  overflow: hidden;
  color: var(--text);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.management-ranked-track {
  height: 8px;
  overflow: hidden;
  background: #eceef3;
}

.management-ranked-bar {
  width: var(--bar-width);
  height: 100%;
  background: var(--brand-blue);
}

.management-ranked-bar.negative {
  background: var(--wine-light);
}

.management-ranked-value {
  color: var(--deep-blue);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.management-chart-empty {
  display: grid;
  min-height: 190px;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}

.management-period-table {
  min-width: 1260px;
}

.accountant-report-table {
  min-width: 1840px;
}

.accountant-report-table tr.accountant-parent-row td {
  background: #f3f5fb;
  color: var(--deep-blue);
  font-weight: 500;
}

.accountant-report-table tr.accountant-placement-row td:first-child,
.accountant-report-table tr.accountant-placement-row td:nth-child(2),
.accountant-report-table tr.accountant-placement-row td:nth-child(3) {
  background: #fafafb;
}

.accountant-report-table tr.accountant-child-row td:nth-child(5) {
  padding-left: 22px;
}

.accountant-report-table td.accountant-direction-incoming {
  color: #176b45;
  font-weight: 600;
}

.accountant-report-table td.accountant-direction-outgoing {
  color: #a12a35;
  font-weight: 600;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px rgba(33, 64, 154, 0.12);
}

input[readonly] {
  background: #f5f6fa;
  color: var(--muted);
  cursor: default;
}

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

#coverEndorsementForm textarea[name="new_premium_payment_schedule"],
#coverEndorsementForm textarea[name="description"],
#coverEndorsementForm textarea[name="notes"],
#contractEndorsementForm textarea[name="new_premium_payment_schedule"],
#contractEndorsementForm textarea[name="description"],
#contractEndorsementForm textarea[name="notes"] {
  height: 38px;
  min-height: 38px;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 39px;
  color: var(--text);
}

.check-label input {
  width: 17px;
  height: 17px;
}

.compact-check {
  align-self: end;
  min-height: 39px;
  padding-bottom: 2px;
}

.compact-check input {
  width: 15px;
  height: 15px;
}

#coverNotesView .period-start {
  grid-column: 1;
}

#coverNotesView .period-check {
  grid-column: 3 / span 2;
}

.full {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.audit-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1px 8px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
  white-space: normal;
}

.audit-meta span {
  overflow-wrap: anywhere;
}

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

.row-actions.compact-actions {
  flex-wrap: nowrap;
  white-space: nowrap;
}

.table-button {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 400;
}

.table-button:hover {
  border-color: var(--brand-blue);
  color: var(--brand-blue);
}

.table-button.danger:hover {
  border-color: #ead1dd;
  color: var(--wine);
}

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
}

.filter-bar strong {
  color: var(--text);
  font-weight: 600;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--brand-blue);
  padding: 0;
  text-align: left;
}

.link-button:hover {
  color: var(--deep-blue);
  text-decoration: underline;
}

.company-name-button {
  font-weight: 600;
}

.message {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand-blue);
  border-radius: 8px;
  padding: 12px 14px;
  background: #ffffff;
  color: var(--text);
}

.message.error {
  border-left-color: var(--danger);
}

.hidden {
  display: none;
}

.settings-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  overflow: auto;
  box-shadow: 0 22px 70px rgba(12, 18, 16, 0.28);
}

.settings-dialog::backdrop {
  background: rgba(12, 18, 16, 0.48);
}

.details-dialog {
  width: min(980px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  overflow: auto;
  box-shadow: 0 22px 70px rgba(12, 18, 16, 0.28);
}

.details-dialog::backdrop {
  background: rgba(12, 18, 16, 0.48);
}

.details-shell {
  display: grid;
  grid-template-rows: auto auto auto;
  min-height: 0;
}

.details-header,
.details-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-soft);
}

.details-header {
  border-bottom: 1px solid var(--line);
}

.details-header h3 {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 500;
}

.details-actions {
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.details-body {
  display: grid;
  gap: 8px;
  overflow: visible;
  padding: 10px 14px;
}

.detail-section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: visible;
}

.detail-section h4 {
  margin: 0;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  padding: 7px 10px;
  color: var(--brand-blue);
  font-size: 12px;
  font-weight: 600;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  align-items: stretch;
  min-width: 0;
}

.detail-item {
  display: grid;
  gap: 3px;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  padding: 7px 10px;
}

.detail-item.wide {
  grid-column: 1 / -1;
}

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

.detail-item strong {
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.detail-item code {
  display: block;
  overflow: visible;
  border-radius: 6px;
  background: #f6f6f8;
  padding: 6px;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  white-space: pre-wrap;
}

.settings-form {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.settings-form.hidden {
  display: none;
}

.dialog-logo {
  display: block;
  width: 180px;
  max-width: 60%;
  height: auto;
}

.settings-form h3 {
  margin: 0 0 4px;
  font-weight: 400;
}

.password-settings {
  display: grid;
  gap: 16px;
  padding: 20px;
  background: #ffffff;
}

.password-settings.hidden {
  display: none;
}

.password-settings h3 {
  margin: 2px 0 0;
  font-size: 18px;
  font-weight: 500;
}

.account-settings-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  padding: 12px;
  background: var(--surface-soft);
}

.account-settings-summary h3,
.account-settings-summary p {
  margin: 0;
}

.account-settings-summary .status-pill {
  display: inline-flex;
  margin-top: 7px;
}

.password-settings-heading {
  padding-top: 2px;
}

.password-form {
  padding: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr;
    padding: 16px;
  }

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

  .connection-card {
    margin-top: 0;
  }

  .content-grid.two,
  .metric-grid,
  .project-payment-summary,
  .report-summary-strip {
    grid-template-columns: 1fr 1fr;
  }

  .dashboard-lower-grid {
    grid-template-columns: 1fr;
  }

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

  .management-summary-strip > div:nth-child(odd) {
    border-right: 1px solid var(--line);
  }

  .management-summary-strip > div:nth-child(even) {
    border-right: 0;
  }

  .management-summary-strip > div:nth-last-child(-n + 4) {
    border-bottom: 1px solid var(--line);
  }

  .management-summary-strip > div:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  .report-filter-grid {
    grid-template-columns: repeat(2, minmax(170px, 1fr));
  }

  .payment-allocation-editor {
    grid-template-columns: repeat(2, minmax(170px, 1fr));
  }

  #companiesView .form-grid,
  #contactsView .form-grid,
  #coverNotesView .form-grid,
  #serviceAgreementsView .form-grid,
  #paymentsView .form-grid,
  .detail-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #coverNotesView .period-check {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 16px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .dashboard-context-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .dashboard-user-card {
    width: 100%;
    min-width: 0;
  }

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

  .dashboard-block-header > small {
    text-align: left;
  }

  .dashboard-finance-grid,
  .dashboard-operation-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-stat,
  .dashboard-stat:last-child,
  .dashboard-operation-stat,
  .dashboard-operation-stat:nth-child(2) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .dashboard-stat:last-child,
  .dashboard-operation-wide {
    border-bottom: 0;
  }

  .dashboard-operation-wide {
    grid-column: auto;
  }

  .nav-list,
  .content-grid.two,
  .metric-grid,
  .project-payment-summary,
  .report-summary-strip,
  .management-summary-strip,
  .form-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .report-dialog {
    width: calc(100vw - 12px);
    height: calc(100dvh - 12px);
  }

  .report-dialog-header {
    align-items: flex-start;
  }

  .report-filter-grid {
    grid-template-columns: 1fr;
    max-height: 42dvh;
    overflow: auto;
  }

  .accrual-period-presets {
    align-items: stretch;
    flex-direction: column;
    gap: 9px;
  }

  .payment-allocation-editor {
    grid-template-columns: 1fr;
  }

  .report-summary-strip > div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .report-summary-strip > div:last-child {
    border-bottom: 0;
  }

  .management-summary-strip > div,
  .management-summary-strip > div:nth-child(odd) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .management-summary-strip > div:nth-last-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .management-summary-strip > div:last-child {
    border-bottom: 0;
  }

  .management-output-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .management-chart-legend {
    justify-content: flex-start;
  }

  .management-analysis-grid {
    grid-template-columns: 1fr;
  }

  .management-analysis-grid > section + section {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .management-counterparty-chart {
    grid-template-columns: 1fr;
  }

  .management-ranked-row {
    grid-template-columns: minmax(100px, 0.85fr) minmax(100px, 1fr) auto;
  }

  .project-payment-summary > div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .project-payment-summary > div:last-child {
    border-bottom: 0;
  }

  .details-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
  }

  .details-header,
  .details-actions {
    padding: 10px 12px;
  }

  #companiesView .table-wrap,
  #contactsView .table-wrap,
  #coverNotesView .table-wrap,
  #serviceAgreementsView .service-agreements-table-wrap,
  #paymentsView .payments-table-wrap {
    max-height: 60dvh;
  }

  .project-header {
    align-items: stretch;
    flex-direction: column;
  }

  .project-actions {
    justify-content: flex-start;
  }

  .search-input {
    width: 100%;
  }

  .panel-tools {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .panel-tools .search-input {
    width: 100%;
  }

  .payment-filter-bar,
  .cover-note-filter-bar {
    align-items: stretch;
  }

  .cover-note-filter-bar .filter-result {
    margin-left: 0;
    width: 100%;
  }

  .segmented-control {
    width: 100%;
    overflow-x: auto;
  }

  .segmented-control button {
    flex: 1 0 auto;
  }

  .compact-filter,
  .compact-filter select,
  .compact-filter input {
    width: 100%;
  }
}
