/* MyCashflow — light slate + teal tool UI */

:root {
  --bg: #e8eef2;
  --bg-elevated: #f7fafb;
  --surface: #ffffff;
  --surface-muted: #f1f5f7;
  --ink: #1a2b34;
  --ink-muted: #5a6f7a;
  --line: #cfd8de;
  --line-soft: #e4ebef;
  --accent: #0d7a6f;
  --accent-hover: #0a635a;
  --accent-soft: #d5f0ec;
  --inflow: #1565c0;
  --outflow: #c62828;
  --parent-row: #eef4f3;
  --cashflow-stripe: #f4f8f9;
  --cashflow-stripe-parent: #e6eeed;
  --shadow: 0 1px 2px rgba(26, 43, 52, 0.06), 0 8px 24px rgba(26, 43, 52, 0.06);
  --radius: 10px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --topbar-h: 56px;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}

body {
  background:
    radial-gradient(circle at 10% 0%, #d7ece8 0%, transparent 45%),
    radial-gradient(circle at 90% 10%, #d9e4ec 0%, transparent 40%),
    var(--bg);
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--topbar-h);
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #1b9a8c);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.lang-select select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  font: inherit;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

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

.btn-save {
  position: relative;
  min-width: 5.75rem;
  overflow: hidden;
}

.btn-save-label,
.btn-save-saved {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.btn-save-saved {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: scale(0.9);
  color: #1a7f4b;
  pointer-events: none;
}

.btn-save-check {
  display: inline-block;
  font-weight: 700;
  transform: scale(0.6);
  opacity: 0;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.18s ease;
}

.btn-save.is-saved {
  border-color: #9dd4b6;
  background: #e8f7ef;
}

.btn-save.is-saved .btn-save-label {
  opacity: 0;
  transform: scale(0.9);
}

.btn-save.is-saved .btn-save-saved {
  opacity: 1;
  transform: scale(1);
}

.btn-save.is-saved .btn-save-check {
  opacity: 1;
  transform: scale(1);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-small {
  padding: 6px 10px;
  font-size: 0.9rem;
}

.btn-danger {
  color: var(--outflow);
  border-color: #f3c6c2;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}

.export-menu {
  position: relative;
}

.export-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 30;
}

.export-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}

.export-menu-item:hover {
  background: var(--surface-muted);
}

.project-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 16px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--line-soft);
}

.company-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-right: 8px;
}

.company-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
}

.company-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-icon {
  min-width: 40px;
  padding-inline: 10px;
  font-size: 1.05rem;
  line-height: 1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field span {
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.field input,
.field textarea,
.field select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  background: var(--surface);
  min-width: 0;
}

.field-inline {
  min-width: 180px;
}

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

.field-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.field-checkbox input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.field-toggle-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.field-toggle-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field-toggle-label {
  font-weight: 600;
  color: var(--ink);
}

.field-toggle-hint {
  font-size: 0.82rem;
  color: var(--ink-muted);
  line-height: 1.35;
}

.toggle-switch {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: relative;
  display: block;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.2s ease;
  box-shadow: inset 0 1px 2px rgba(26, 43, 52, 0.12);
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(26, 43, 52, 0.2);
  transition: transform 0.2s ease;
}

.toggle-switch input:checked + .toggle-track {
  background: var(--accent);
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(18px);
}

.toggle-switch input:focus-visible + .toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field-toggle-row.is-auto {
  opacity: 0.92;
}

.field-toggle-row.is-auto .toggle-switch {
  cursor: not-allowed;
}

.field-toggle-row.is-auto .toggle-switch input:disabled + .toggle-track {
  opacity: 0.75;
}

.recurrence-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.event-recurring-badge {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-soft, #e8f0fe);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 600;
  vertical-align: middle;
}

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

.file-hint {
  margin-left: auto;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.file-hint-saved-at {
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 16px 0;
}

.tab {
  border: 0;
  background: transparent;
  padding: 12px 18px;
  border-radius: 10px 10px 0 0;
  font: inherit;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
}

.tab.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.main {
  flex: 1;
  padding: 0 16px 24px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  box-shadow: var(--shadow);
  min-height: 420px;
  position: relative;
}

.panel[hidden] {
  display: none !important;
}

.events-layout {
  display: grid;
  grid-template-columns: minmax(180px, 24%) minmax(0, 1fr);
  gap: 0;
  min-height: 520px;
}

.events-list-panel,
.events-editor-panel {
  padding: 16px;
  min-width: 0;
}

.events-list-panel {
  border-right: 1px solid var(--line-soft);
  overflow: auto;
}

.events-list-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.events-list-toolbar {
  display: flex;
  justify-content: flex-end;
}

.events-columns-menu {
  position: relative;
}

.events-columns-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 15;
  min-width: 190px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.events-columns-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.events-columns-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  cursor: pointer;
}

.events-columns-reset {
  width: 100%;
}

.events-editor-panel {
  overflow: auto;
}

.editor-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  color: var(--ink-muted);
}

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

.section-head h3 {
  margin: 0;
  font-size: 1rem;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.table-scroll {
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  background: var(--surface-muted);
  color: var(--ink-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table input {
  width: 100%;
  min-width: 70px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
}

.events-row {
  cursor: pointer;
}

.events-row:hover {
  background: var(--surface-muted);
}

.events-row.is-selected {
  background: var(--accent-soft);
}

.events-list .cell-input {
  width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  background: transparent;
}

.events-list .cell-input:hover,
.events-list .cell-input:focus {
  border-color: var(--line);
  background: var(--surface);
}

.events-list .cell-date {
  max-width: 110px;
  font-family: var(--mono);
  font-size: 0.88rem;
}

.events-list .cell-name {
  font-weight: 600;
}

.events-list .cell-description {
  min-width: 140px;
}

.events-list .cell-readonly {
  color: var(--ink-muted);
  white-space: nowrap;
}

.events-list .cell-net {
  font-family: var(--mono);
  font-size: 0.88rem;
}

.event-name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.event-name-content {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.event-name-content .cell-name {
  flex: 1;
}

.event-type-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.event-type-text {
  min-width: 0;
}

.event-type-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 9px;
  flex-shrink: 0;
  background: var(--event-type-bg, var(--surface-muted));
  color: var(--event-type-color, var(--ink-muted));
  box-shadow: inset 0 0 0 1px rgba(26, 43, 52, 0.06);
}

.event-type-icon svg {
  width: 1.05rem;
  height: 1.05rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.event-type-icon--sm {
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 7px;
}

.event-type-icon--sm svg {
  width: 0.9rem;
  height: 0.9rem;
}

.by-type-table .event-type-label {
  font-weight: 600;
}

.cashflow-table .event-type-label {
  align-items: flex-start;
}

.cashflow-table .impact-indent,
.cashflow-table .occurrence-indent {
  display: inline;
}

.impacts-table .impact-name {
  min-width: 140px;
}

.impact-schedule-cell {
  min-width: 260px;
}

.impact-schedule-mode {
  width: 100%;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  background: var(--surface);
}

.impact-schedule-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.schedule-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.schedule-row input,
.schedule-row select,
.impact-schedule-fields > .impact-date {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  background: var(--surface);
}

.impact-schedule-fields .impact-days {
  width: 72px;
}

.loan-fields {
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.loan-summary {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
  color: var(--ink);
  font-size: 0.92rem;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.loan-summary span {
  font-family: var(--mono);
}

.loan-summary-sep {
  color: var(--ink-muted);
}

.event-summary {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--ink);
  font-size: 0.92rem;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.event-summary span {
  font-family: var(--mono);
}

.event-summary-inflow {
  color: var(--inflow);
}

.event-summary-outflow {
  color: var(--outflow);
}

.event-summary-net {
  font-weight: 600;
}

.event-summary-occurrences {
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 0.85rem;
}

.event-summary-sep {
  color: var(--ink-muted);
  font-family: inherit;
}

.repayment-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}

.repayment-fields select,
.repayment-fields input:not(.repayment-calc-readonly):not(.money-input) {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  background: var(--surface);
}

.money-input,
.repayment-fields .money-input,
.impacts-table .money-input,
.field-inline .money-input {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-family: var(--mono);
  background: var(--surface);
  text-align: right;
}

.repayment-calc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
}

.repayment-calc-label {
  color: var(--ink-muted);
  white-space: nowrap;
}

.repayment-calc-value {
  font-family: var(--mono);
  color: var(--ink);
}

.repayment-calc-readonly {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-family: var(--mono);
  background: var(--surface-muted);
  color: var(--ink);
  text-align: right;
  cursor: default;
}

.repayment-summary {
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.amount-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
}

.amount-cell .amount-mode {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
  background: var(--surface);
}

.line-items-editor {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.line-items-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.line-item-row {
  display: grid;
  grid-template-columns: minmax(80px, 1.4fr) minmax(72px, 1fr) 56px minmax(72px, 0.9fr) 24px;
  gap: 4px;
  align-items: center;
}

.line-item-row input {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
  background: var(--surface);
  min-width: 0;
}

.line-item-row .line-item-unit {
  font-family: var(--mono);
  text-align: right;
}

.line-item-row .line-item-qty {
  text-align: right;
}

.line-item-total {
  font-family: var(--mono);
  font-size: 0.82rem;
  text-align: right;
  white-space: nowrap;
}

.line-items-total {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--line-soft);
  font-size: 0.82rem;
}

.line-items-total-label {
  color: var(--ink-muted);
}

.line-items-total-value {
  font-family: var(--mono);
  font-weight: 600;
}

.btn-remove-line-item {
  padding: 0;
  width: 24px;
  height: 24px;
  line-height: 1;
}

.impact-schedule-fields .impact-ref-flow,
.impact-schedule-fields .impact-ref-event {
  flex: 1 1 160px;
  min-width: 140px;
}

.schedule-label {
  color: var(--ink-muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.impact-schedule-preview {
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.impacts-table .is-empty {
  opacity: 0.75;
}

.impacts-table.hide-inflow-col .col-inflow,
.impacts-table.hide-inflow-col td:nth-child(3) {
  display: none;
}

.impacts-table.hide-outflow-col .col-outflow,
.impacts-table.hide-outflow-col td:nth-child(4) {
  display: none;
}

.event-summary .is-hidden {
  display: none;
}

.impact-parcelar-controls {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.impact-parcelar-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--ink-muted);
  cursor: pointer;
}

.impact-parcelar-count-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.impact-parcelar-count {
  width: 4.5rem;
}

.impact-parcelar-hint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.impact-name-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.impact-row-installment-auto {
  background: rgba(241, 245, 247, 0.65);
}

.impact-row-iof {
  background: color-mix(in srgb, var(--accent-soft) 35%, var(--surface));
}

.repayment-iof-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line-soft);
}

.repayment-iof-row .toggle-switch {
  flex-shrink: 0;
}

.impact-name-readonly,
.impact-schedule-readonly,
.impact-readonly-amount {
  color: var(--ink-muted);
}

.impact-readonly-amount {
  width: 100%;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: var(--mono);
  font-size: 0.88rem;
  background: var(--surface);
}

.cashflow-view-root,
.by-type-view-root {
  position: relative;
  min-height: 0;
}

.selectable-row {
  cursor: pointer;
}

.selectable-row.is-selected {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 65%, transparent);
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface)) !important;
}

.selection-summary-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  width: min(280px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(15, 35, 40, 0.16);
}

.panel[hidden] .selection-summary-panel {
  display: none !important;
}

.selection-summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.selection-summary-title {
  font-size: 0.92rem;
  font-weight: 700;
}

.selection-summary-clear {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--ink-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.selection-summary-clear:hover {
  background: var(--line-soft);
  color: var(--ink);
}

.selection-summary-count {
  margin: 0 0 10px;
  color: var(--ink-muted);
  font-size: 0.82rem;
}

.selection-summary-stats {
  display: grid;
  gap: 8px;
  margin: 0;
}

.selection-summary-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.selection-summary-stat dt {
  margin: 0;
  font-size: 0.84rem;
  color: var(--ink-muted);
}

.selection-summary-stat dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.92rem;
  font-weight: 600;
}

.cashflow-view-root {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.cashflow-filter-shell {
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
}

.cashflow-filter-bar {
  display: flex;
  justify-content: flex-end;
  padding: 10px 16px 0;
}

.cashflow-filter-toggle {
  color: var(--ink-muted);
  border-color: var(--line-soft);
  background: var(--surface);
}

.cashflow-filter-toggle:hover {
  color: var(--ink);
  background: var(--surface-muted);
}

.cashflow-filter-toggle.is-open {
  color: var(--ink);
  background: var(--surface-muted);
  border-color: var(--line);
}

.cashflow-filter-toggle.is-active:not(.is-open) {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line-soft));
}

.cashflow-filters-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 10px 16px 14px;
}

.cashflow-filters-panel[hidden] {
  display: none;
}

.cashflow-filter-search {
  width: 100%;
  max-width: 420px;
}

.cashflow-filter-search input {
  width: 100%;
}

.cashflow-filter-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  padding: 12px 14px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-muted) 88%, var(--accent) 12%);
  border: 1px solid color-mix(in srgb, var(--line-soft) 80%, var(--accent) 20%);
}

.cashflow-filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.cashflow-filter-heading {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cashflow-period-options,
.cashflow-type-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cashflow-period-option,
.cashflow-type-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.88rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.cashflow-period-option:hover,
.cashflow-type-option:hover {
  border-color: var(--line);
}

.cashflow-period-option:has(input:checked),
.cashflow-type-option:has(input:checked) {
  color: var(--ink);
  background: color-mix(in srgb, var(--surface) 70%, var(--accent) 30%);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}

.cashflow-period-option input,
.cashflow-type-option input {
  margin: 0;
}

.cashflow-custom-range {
  max-width: 420px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.cashflow-custom-range[hidden] {
  display: none;
}

.cashflow-table-host {
  min-height: 0;
}

.cashflow-filter-meta {
  margin: 12px 16px 0;
  color: var(--ink-muted);
  font-size: 0.88rem;
}

.cashflow-filter-empty {
  padding: 24px 16px;
}

.cashflow-scroll {
  padding: 16px;
}

.by-type-scroll {
  padding: 16px;
}

.by-type-group-row.is-expandable {
  cursor: pointer;
}

.by-type-group-row.is-expandable:hover {
  background: var(--surface-muted);
}

.by-type-type-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.by-type-expand,
.by-type-expand-spacer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
}

.by-type-expand {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.by-type-expand:hover {
  background: var(--line-soft);
  color: var(--ink);
}

.by-type-type-label {
  min-width: 0;
}

.by-type-detail-row {
  background: var(--surface-muted);
}

.by-type-detail-row td {
  border-top: 1px solid var(--line-soft);
  font-size: 0.92rem;
}

.by-type-detail-cell {
  padding-left: 2.35rem;
}

.by-type-detail-name {
  font-weight: 600;
}

.by-type-detail-date {
  margin-top: 2px;
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.by-type-table td:nth-child(2) {
  text-align: center;
  font-family: var(--mono);
}

.by-type-table tfoot .by-type-totals td:nth-child(2) {
  text-align: center;
  font-family: var(--mono);
}

.dre-view-root {
  position: relative;
  min-height: 0;
}

.dre-header {
  padding: 16px 16px 0;
}

.dre-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.dre-top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px 0;
}

.dre-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 0;
}

.dre-share-menu {
  flex-shrink: 0;
  margin-top: 2px;
}

.dre-share-btn {
  color: var(--ink-muted);
  border-color: transparent;
  background: transparent;
}

.dre-share-btn:hover,
.dre-share-btn[aria-expanded="true"] {
  color: var(--ink);
  background: var(--surface-muted);
  border-color: var(--line-soft);
}

.dre-share-icon {
  display: block;
  width: 18px;
  height: 18px;
}

.dre-version-select-wrap {
  min-width: 280px;
}

.dre-version-select {
  min-width: 240px;
}

.dre-version-panel {
  margin: 0 16px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.dre-version-panel[hidden] {
  display: none !important;
}

.dre-version-editor {
  display: grid;
  gap: 14px;
}

.dre-version-dates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.dre-version-items {
  margin: 0;
  padding: 12px 14px 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
}

.dre-version-items legend {
  padding: 0 4px;
  font-weight: 600;
}

.dre-version-item {
  margin-top: 8px;
}

.dre-version-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dre-period-meta {
  margin: 6px 0 0;
  color: var(--ink-muted);
  font-size: 0.86rem;
}

.dre-subtitle {
  margin: 4px 0 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.dre-scroll {
  padding: 16px;
}

.dre-empty {
  padding: 8px 0 24px;
}

.dre-table {
  width: 100%;
  max-width: 920px;
  border-collapse: collapse;
}

.dre-line td {
  padding: 12px 0;
  vertical-align: top;
  border-bottom: 1px solid var(--line-soft);
}

.dre-line--subtotal td,
.dre-line--total td {
  border-bottom-color: var(--line);
}

.dre-line--subtotal .dre-label {
  font-weight: 700;
}

.dre-line--total .dre-label {
  font-weight: 700;
  font-size: 1.02rem;
}

.dre-line--deduction .dre-label {
  padding-left: 16px;
  color: var(--ink);
}

.dre-line--deduction .dre-hint,
.dre-line--subtotal .dre-hint,
.dre-line--total .dre-hint {
  padding-left: 16px;
}

.dre-label {
  font-size: 0.95rem;
}

.dre-hint {
  margin-top: 3px;
  color: var(--ink-muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.dre-amount-cell {
  width: 180px;
  text-align: right;
  font-family: var(--mono);
  font-size: 0.95rem;
  white-space: nowrap;
}

.dre-line--subtotal .dre-amount-cell,
.dre-line--total .dre-amount-cell {
  font-weight: 700;
}

.dre-amount-cell.is-negative {
  color: var(--danger, #c62828);
}

.dre-line--total .dre-amount-cell {
  font-size: 1.05rem;
}

.chart-panel {
  padding: 16px;
  position: relative;
}

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.chart-type-field select {
  min-width: 180px;
}

.chart-tooltip {
  position: absolute;
  z-index: 20;
  min-width: 220px;
  max-width: 320px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  pointer-events: none;
  font-size: 0.82rem;
  line-height: 1.45;
}

.chart-tooltip-title {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 2px;
}

.chart-tooltip-sub {
  color: var(--ink-muted);
  font-size: 0.78rem;
  margin-bottom: 8px;
}

.chart-tooltip-summary {
  font-family: var(--mono);
  font-weight: 600;
  margin-top: 8px;
}

.chart-tooltip-summary:first-of-type {
  margin-top: 4px;
}

.chart-tooltip-balance {
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  margin-top: 10px;
}

.chart-tooltip-list {
  margin: 4px 0 0;
  padding-left: 16px;
  list-style: disc;
}

.chart-tooltip-list li {
  font-family: var(--mono);
  font-size: 0.78rem;
  margin: 2px 0;
}

.chart-tooltip-muted {
  color: var(--ink-muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.chart-hit-zone {
  cursor: crosshair;
}

.chart-bar,
.chart-balance-dot,
.chart-series-dot {
  cursor: pointer;
}

.chart-balance-area {
  pointer-events: none;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  margin-bottom: 12px;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.chart-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.chart-swatch-inflow {
  background: var(--inflow);
}

.chart-swatch-outflow {
  background: var(--outflow);
}

.chart-swatch-balance {
  background: var(--ink);
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px var(--inflow);
}

.chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
}

.cashflow-chart {
  display: block;
  min-width: 100%;
}

.chart-axis-label {
  fill: var(--ink-muted);
  font-size: 11px;
  font-family: var(--mono);
}

.chart-x-label {
  font-family: var(--font);
  font-size: 10px;
}

.chart-balance-line {
  pointer-events: none;
}

.cashflow-scroll .cashflow-table tbody tr:nth-child(even) {
  background: var(--cashflow-stripe);
}

.cashflow-scroll .cashflow-table tbody tr:nth-child(odd) {
  background: var(--surface);
}

.cashflow-scroll .cashflow-table .row-parent {
  font-weight: 600;
}

.cashflow-scroll .cashflow-table tbody tr.row-parent:nth-child(odd),
.cashflow-scroll .cashflow-table tbody tr.row-occurrence:nth-child(odd) {
  background: var(--parent-row);
}

.cashflow-scroll .cashflow-table tbody tr.row-parent:nth-child(even),
.cashflow-scroll .cashflow-table tbody tr.row-occurrence:nth-child(even) {
  background: var(--cashflow-stripe-parent);
}

.cashflow-scroll .cashflow-table .row-parent td:first-child {
  border-left: 3px solid var(--accent);
}

.cashflow-scroll .cashflow-table .row-occurrence {
  font-weight: 600;
  color: var(--ink-muted);
}

.cashflow-scroll .cashflow-table .row-occurrence td:first-child {
  border-left: 3px solid var(--accent);
}

.occurrence-indent {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-left: 4px;
  font-size: 0.92rem;
}

.cashflow-table tfoot .cashflow-totals td {
  border-top: 2px solid var(--line);
  font-weight: 600;
  background: var(--surface-muted);
}

.cashflow-table tfoot .cashflow-totals td:nth-child(3),
.cashflow-table tfoot .cashflow-totals td:nth-child(4) {
  font-family: var(--mono);
}

.impact-indent {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding-left: 8px;
  font-weight: 500;
}

.impact-bullet {
  color: var(--accent);
  font-weight: 700;
}

.amount-in {
  color: var(--inflow);
  font-family: var(--mono);
  font-weight: 600;
}

.amount-out {
  color: var(--outflow);
  font-family: var(--mono);
  font-weight: 600;
}

.amount-balance {
  font-family: var(--mono);
}

.empty-hint {
  color: var(--ink-muted);
  padding: 12px 0;
}

.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 43, 52, 0.35);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-card--wide {
  width: min(640px, 100%);
}

.modal-card--settings {
  width: min(860px, 100%);
}

.report-layout-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: end;
}

.report-layout-colors {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.report-layout-size-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.report-layout-visibility {
  display: grid;
  gap: 8px;
}

.report-layout-orientation {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
}

.report-layout-orientation legend {
  padding: 0 4px;
  font-weight: 600;
}

.report-orientation-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.report-orientation-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}

.report-layout-color-field input[type="color"] {
  width: 56px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.report-layout-editor {
  display: grid;
  gap: 8px;
}

.report-layout-editor-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.88rem;
}

.report-layout-editor-hint {
  color: var(--ink-muted);
}

.report-layout-canvas-wrap {
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.report-layout-canvas {
  --report-primary: #334155;
  --report-text: #1a2b34;
  --report-muted: #5a6f7a;
  --report-negative: #c62828;
  --report-header-text: #ffffff;
  margin: 0 auto;
  max-width: 100%;
}

.report-layout-canvas.is-landscape .report-layout-sheet-preview {
  aspect-ratio: 1.414 / 1;
}

.report-layout-sheet-preview {
  position: relative;
  aspect-ratio: 1 / 1.414;
  max-height: 360px;
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.report-layout-item {
  position: absolute;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transform: translate(-50%, -50%);
  z-index: 2;
}

.report-layout-item.is-dragging {
  cursor: grabbing;
  z-index: 3;
}

.report-layout-logo img {
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.report-layout-name {
  padding: 4px 8px;
  border: 1px dashed color-mix(in srgb, var(--report-primary) 35%, var(--line));
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.85);
  font-weight: 700;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.report-layout-content-area {
  position: absolute;
  box-sizing: border-box;
  border: 2px dashed color-mix(in srgb, var(--report-primary) 55%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--report-primary) 6%, #fff);
  cursor: grab;
  z-index: 1;
  overflow: hidden;
}

.report-layout-content-area.is-dragging {
  cursor: grabbing;
  z-index: 2;
}

.report-layout-content-label {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--report-primary);
  pointer-events: none;
}

.report-layout-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--report-primary) 50%);
  border-bottom-right-radius: 6px;
}

.report-layout-resize-handle.is-dragging {
  cursor: nwse-resize;
}

.report-layout-body-preview {
  padding: 28px 12px 12px;
  display: grid;
  gap: 8px;
  align-content: start;
  height: 100%;
  box-sizing: border-box;
  pointer-events: none;
}

.report-layout-title-bar {
  font-weight: 700;
  color: var(--report-primary);
}

.report-layout-line {
  height: 8px;
  border-radius: 999px;
  background: var(--line-soft);
}

.report-layout-line--short {
  width: 62%;
}

.settings-modal-body {
  display: grid;
  gap: 20px;
}

.settings-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line-soft);
  margin: -4px 0 0;
}

.settings-tab {
  border: 0;
  background: transparent;
  padding: 10px 14px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.settings-tab:hover {
  color: var(--ink);
}

.settings-tab.is-active {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.settings-tab-panel[hidden] {
  display: none !important;
}

.settings-section {
  display: grid;
  gap: 12px;
}

.settings-section + .settings-section {
  padding-top: 4px;
  border-top: 1px solid var(--line-soft);
}

.settings-section-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.settings-field-hint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.settings-logo-field {
  display: grid;
  gap: 8px;
}

.settings-logo-label {
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.settings-logo-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.settings-logo-preview {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
}

.settings-logo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-logo-upload {
  position: relative;
  cursor: pointer;
}

.company-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.company-header-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--line-soft);
  background: var(--surface);
}

.company-header-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

.modal-header,
.modal-footer {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.modal-footer {
  border-bottom: 0;
  border-top: 1px solid var(--line-soft);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-body {
  padding: 16px;
}

.open-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.open-path {
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.open-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.open-list-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}

.open-list-item:last-child {
  border-bottom: 0;
}

.open-list-item:hover {
  background: var(--surface-muted);
}

.open-list-item.is-selected {
  background: var(--accent-soft);
}

.fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(13, 122, 111, 0.35), var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}

.fab:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

.fab:active {
  transform: translateY(0);
}

.fab-icon {
  font-size: 1.75rem;
  line-height: 1;
  font-weight: 400;
}

.fab[hidden] {
  display: none !important;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 60;
}

.toast.is-error {
  background: var(--outflow);
}

@media (max-width: 900px) {
  .fab {
    right: 16px;
    bottom: 16px;
  }

  .events-layout {
    grid-template-columns: 1fr;
  }

  .events-list-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    max-height: 280px;
  }

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

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

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

  .file-hint {
    margin-left: 0;
    width: 100%;
  }

  .cashflow-filter-shell {
    padding-bottom: 8px;
  }

  .cashflow-filter-bar {
    padding-top: 8px;
  }

  .cashflow-filters-panel {
    padding-top: 8px;
  }

  .cashflow-filter-groups {
    flex-direction: column;
  }
}

@media print {
  .topbar,
  .project-bar,
  .tabs,
  .toast,
  .modal,
  .fab,
  .cashflow-filter-shell,
  .cashflow-filter-meta,
  .selection-summary-panel,
  #panel-events {
    display: none !important;
  }

  body {
    background: #fff;
  }

  #panel-cashflow {
    display: block !important;
  }

  #panel-cashflow[hidden] {
    display: block !important;
  }

  .panel {
    border: 0;
    box-shadow: none;
  }

  .main,
  .panel,
  .cashflow-scroll {
    padding: 0;
  }

  .cashflow-table tbody tr:nth-child(even) {
    background: #f4f4f4 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .cashflow-table .row-parent,
  .cashflow-table .row-occurrence {
    background: #f5f5f5 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .cashflow-table tbody tr.row-parent:nth-child(even),
  .cashflow-table tbody tr.row-occurrence:nth-child(even) {
    background: #ececec !important;
  }

  .amount-in,
  .amount-out {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
