.cash-flow-layout {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cash-flow-layout > #cash-tab-content {
  flex: 1 1 auto;
  overflow: hidden;
}

.cash-flow-shell {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.cash-flow-shell .sidebar,
.cash-flow-shell .main,
.cash-flow-shell .content,
.cash-flow-shell .cash-flow-layout,
.cash-flow-shell #cash-tab-content {
  min-height: 0;
}

.cash-flow-shell .content {
  overflow: hidden;
}

.cash-flow-shell .main {
  height: 100%;
}

.cash-flow-shell .cash-flow-layout {
  height: 100%;
}

.cash-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 12px;
  min-height: 0;
}

.cash-head h2,
.cash-head p {
  margin: 0;
}

.cash-head h2 {
  font-size: 19px;
}

.cash-head p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.cash-kicker {
  color: var(--brand);
  font: 800 10px/1.5 Inter, sans-serif;
}

.cash-head-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.cash-head-actions label {
  min-width: 145px;
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.cash-head-actions input,
.cash-head-actions select {
  min-height: 34px;
  height: 34px;
  padding-block: 5px;
}

.cash-head-actions button {
  min-height: 34px;
  padding-block: 5px;
}

.cash-kpi-grid {
  height: 66px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.cash-overdue-alert {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 11px;
  color: #8f3128;
  border: 1px solid color-mix(in srgb, #dc6b5f 35%, var(--line-soft));
  border-radius: 8px;
  background: color-mix(in srgb, #dc6b5f 9%, var(--panel-strong));
}

.cash-overdue-alert span {
  flex: 1;
  color: var(--muted);
  font-size: 11px;
}

.cash-overdue-alert button {
  min-height: 28px;
  padding: 3px 10px;
  color: #fff;
  background: #a1372c;
}

.cash-kpi {
  height: 66px;
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 9px 11px;
  border-top: 3px solid var(--line-soft);
}

.cash-kpi span,
.cash-kpi small {
  color: var(--muted);
  font-size: 11px;
}

.cash-kpi strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 17px;
  text-overflow: ellipsis;
}

.cash-kpi-inflow {
  border-top-color: var(--brand);
}

.cash-kpi-outflow,
.cash-kpi-danger {
  border-top-color: #dc6b5f;
}

.cash-kpi-safe {
  border-top-color: #0284c7;
}

.cash-chart-panel {
  height: 108px;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 9px 12px;
  overflow: hidden;
}

.cash-chart-panel .toolbar {
  min-height: 0;
  align-items: center;
  margin-bottom: 2px;
  gap: 6px;
}

.cash-chart-panel .panel-title {
  margin: 0;
  font-size: 14px;
}

.cash-chart-panel .panel-subtitle {
  margin: 0;
  font-size: 10px;
}

.cash-alert-badge,
.cash-safe-badge {
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.cash-alert-badge {
  color: #a1372c;
  background: #fff0ed;
}

.cash-safe-badge {
  color: #007864;
  background: #e4f7f2;
}

.cash-chart {
  height: 68px;
  display: flex;
  align-items: end;
  gap: 4px;
  padding: 8px 4px 0;
  overflow-x: auto;
  direction: rtl;
  border-bottom: 1px solid var(--line-soft);
}

.cash-chart-column {
  width: max(32px, calc((100% - 76px) / 20));
  min-width: 32px;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 19px;
  align-items: end;
  padding: 0;
  color: var(--muted);
  border: 0;
  background: transparent;
}

.cash-chart-column span {
  width: 72%;
  min-height: 5px;
  justify-self: center;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, var(--brand), color-mix(in srgb, var(--brand) 58%, var(--navy)));
}

.cash-chart-column.is-low span {
  background: #dc6b5f;
}

.cash-chart-column small {
  font-size: 9px;
  white-space: nowrap;
}

.cash-tabs {
  width: fit-content;
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: var(--panel-strong);
}

.cash-tabs button {
  min-height: 32px;
  padding: 5px 13px;
  color: var(--muted);
  border: 0;
  background: transparent;
}

.cash-tabs button.active {
  color: #fff;
  background: var(--navy);
}

.cash-forecast-panel {
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 10px 12px;
  overflow: hidden;
}

.cash-forecast-toolbar {
  margin-bottom: 7px;
  align-items: center;
  gap: 6px;
}

.cash-forecast-toolbar .panel-title,
.cash-forecast-toolbar .panel-subtitle {
  margin: 0;
}

.cash-forecast-toolbar .panel-title {
  font-size: 14px;
}

.cash-forecast-toolbar .panel-subtitle {
  font-size: 10px;
}

.cash-legend {
  display: flex;
  gap: 10px;
  font-size: 11px;
}

.cash-legend span::before {
  content: "";
  width: 8px;
  height: 8px;
  display: inline-block;
  margin-left: 5px;
  border-radius: 2px;
}

.cash-legend .inflow::before {
  background: var(--brand);
}

.cash-legend .outflow::before {
  background: #dc6b5f;
}

.cash-legend .balance::before {
  background: var(--navy);
}

.cash-table-scroll {
  min-height: 0;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
}

.cash-forecast-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 11px;
}

.cash-forecast-table th,
.cash-forecast-table td {
  min-width: 104px;
  height: 44px;
  padding: 8px 9px;
  text-align: center;
  border-left: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-strong);
}

.cash-forecast-table thead th {
  position: sticky;
  z-index: 3;
  top: 0;
  color: var(--ink);
  background: var(--row-bg);
}

.cash-forecast-table thead small,
.cash-sticky-title small {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 400;
}

.cash-forecast-table .cash-sticky-title {
  min-width: 210px;
  position: sticky;
  z-index: 2;
  right: 0;
  text-align: right;
  box-shadow: -6px 0 12px rgba(16, 42, 67, .04);
}

.cash-forecast-table thead .cash-sticky-title {
  z-index: 4;
}

.cash-sticky-title i {
  width: 4px;
  height: 26px;
  display: inline-block;
  margin-left: 7px;
  vertical-align: middle;
  border-radius: 2px;
  background: var(--cash-row-color);
}

.cash-section-row th {
  height: 34px;
  padding: 5px 12px;
  text-align: right;
}

.cash-section-row.inflow th {
  color: #007864;
  background: color-mix(in srgb, var(--brand) 9%, var(--panel-strong));
}

.cash-section-row.outflow th {
  color: #a1372c;
  background: color-mix(in srgb, #dc6b5f 9%, var(--panel-strong));
}

.cash-summary-row th,
.cash-summary-row td,
.cash-balance-row th,
.cash-balance-row td {
  font-weight: 800;
}

.cash-summary-row.inflow td {
  color: #007864;
}

.cash-summary-row.outflow td {
  color: #a1372c;
}

.cash-balance-row td,
.cash-balance-row th {
  color: #fff;
  background: var(--navy);
}

.cash-balance-row td.is-low {
  background: #a1372c;
}

.cash-empty-row {
  color: var(--muted);
}

.cash-entry-list {
  min-height: 0;
  display: grid;
  gap: 7px;
}

.cash-filter-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px 180px;
  gap: 8px;
  margin: 12px 0;
}

.cash-flow-shell .cash-entries-panel {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.cash-flow-shell .cash-entry-list {
  align-content: start;
  overflow-y: auto;
}

.cash-entry-card {
  min-width: 0;
  display: grid;
  grid-template-columns: 38px minmax(180px, 1fr) 130px 150px auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--row-bg);
}

.cash-entry-card.is-overdue {
  border-inline-start: 3px solid #dc6b5f;
}

.cash-entry-card.is-overdue .cash-entry-date small {
  color: #a1372c;
  font-weight: 800;
}

.cash-entry-direction {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 50%;
  font-weight: 900;
}

.cash-entry-direction.inflow {
  background: var(--brand);
}

.cash-entry-direction.outflow {
  background: #dc6b5f;
}

.cash-entry-main,
.cash-entry-date {
  min-width: 0;
  display: grid;
}

.cash-entry-main strong,
.cash-entry-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cash-entry-main small,
.cash-entry-date small {
  color: var(--muted);
  font-size: 10px;
}

.cash-entry-card > b {
  direction: ltr;
  text-align: right;
}

.cash-entry-card > b.inflow {
  color: #007864;
}

.cash-entry-card > b.outflow {
  color: #a1372c;
}

.cash-entry-actions {
  display: flex;
  gap: 4px;
}

.cash-flow-type-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cash-flow-type-control label {
  cursor: pointer;
}

.cash-flow-type-control input {
  position: absolute;
  opacity: 0;
}

.cash-flow-type-control span {
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--row-bg);
}

.cash-flow-type-control input:checked + span {
  color: #fff;
  border-color: var(--navy);
  background: var(--navy);
}

.cash-settings-layout {
  display: grid;
  gap: 16px;
}

.cash-settings-layout h4 {
  margin: 0;
}

.cash-settings-general,
.cash-settings-section {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.cash-settings-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.cash-settings-list > div {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto 36px 36px;
  gap: 7px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--row-bg);
}

.cash-settings-list small {
  color: var(--muted);
}

.cash-setting-state,
.cash-setting-color {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line-soft);
}

.cash-setting-state.active {
  background: var(--brand);
}

.cash-setting-color {
  background: var(--cash-row-color);
}

@media (max-width: 1100px) {
  .cash-kpi-grid {
    height: 56px;
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .cash-flow-shell {
    height: 100dvh;
  }

  .cash-flow-shell .content {
    padding: 7px;
  }

  .cash-flow-layout {
    gap: 7px;
  }

  .cash-head {
    align-items: stretch;
    flex-direction: column;
    gap: 7px;
    padding: 8px;
  }

  .cash-head > div:first-child {
    width: 100%;
  }

  .cash-head h2 {
    font-size: 16px;
  }

  .cash-head p,
  .cash-kicker {
    display: none;
  }

  .cash-head-actions {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr 1fr;
    align-items: end;
    gap: 5px;
  }

  .cash-head-actions label,
  .cash-head-actions button {
    min-width: 0;
    width: 100%;
  }

  .cash-head-actions label {
    font-size: 9px;
  }

  .cash-head-actions button {
    padding-inline: 5px;
    font-size: 10px;
  }

  .cash-overdue-alert {
    min-height: 0;
    flex-wrap: wrap;
    gap: 4px 8px;
    padding: 6px 8px;
    font-size: 10px;
  }

  .cash-overdue-alert span {
    flex: 1 1 180px;
    font-size: 9px;
  }

  .cash-kpi-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }

  .cash-kpi:last-child {
    grid-column: auto;
  }

  .cash-kpi {
    height: 56px;
    gap: 1px;
    padding: 6px 4px;
    text-align: center;
  }

  .cash-kpi span,
  .cash-kpi small {
    font-size: 8px;
  }

  .cash-kpi strong {
    font-size: 12px;
  }

  .cash-chart-panel {
    height: 70px;
    padding: 6px 8px;
  }

  .cash-chart-panel .toolbar {
    display: none;
  }

  .cash-chart {
    height: 58px;
    padding-top: 3px;
  }

  .cash-tabs {
    padding: 2px;
  }

  .cash-tabs button {
    min-height: 28px;
    padding: 4px 9px;
    font-size: 10px;
  }

  .cash-forecast-panel {
    padding: 7px;
  }

  .cash-forecast-toolbar {
    display: none;
  }

  .cash-filter-bar {
    grid-template-columns: 1fr;
  }

  .cash-entry-card {
    grid-template-columns: 34px minmax(0, 1fr) auto;
  }

  .cash-entry-date {
    grid-column: 2;
  }

  .cash-entry-card > b {
    grid-column: 3;
    grid-row: 2;
  }

  .cash-entry-actions {
    grid-column: 2 / -1;
  }

  .cash-legend {
    width: 100%;
  }
}
