.variable-row-tools {
  display: flex;
  direction: ltr;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.variable-details-toggle {
  display: grid;
  flex: 0 0 auto;
  width: 31px;
  height: 31px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: rgba(158, 177, 197, 0.62);
  background: rgba(255, 255, 255, 0.025);
  box-shadow: none;
  cursor: pointer;
  transition:
    color 180ms ease,
    border-color 180ms ease,
    background 180ms ease,
    box-shadow 180ms ease;
}

.variable-details-toggle.has-details {
  border-color: rgba(113, 201, 255, 0.62);
  color: #9de3ff;
  background: rgba(113, 201, 255, 0.09);
  box-shadow: 0 0 10px rgba(113, 201, 255, 0.16);
}

.variable-details-toggle.has-details:hover {
  border-color: rgba(113, 201, 255, 0.94);
  background: rgba(113, 201, 255, 0.18);
  box-shadow: 0 0 13px rgba(113, 201, 255, 0.28);
}

.variable-details-toggle:not(.has-details):hover {
  border-color: rgba(158, 177, 197, 0.45);
  color: #b5c5d5;
  background: rgba(255, 255, 255, 0.055);
}

.variable-details-chevron {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 180ms ease;
}

.variable-details-toggle.is-open .variable-details-chevron {
  transform: rotate(180deg);
}

.variable-details-heading {
  display: grid;
  gap: 4px;
  align-self: center;
}

.variable-details-heading strong {
  color: #dff5ff;
}

.variable-details-heading span {
  color: var(--muted);
  font-size: 0.78rem;
}

.variable-details-fields {
  display: grid;
  grid-template-columns: minmax(155px, 0.72fr) minmax(220px, 1.28fr);
  gap: 14px;
}

.variable-transactions-breakdown {
  display: grid;
  overflow: hidden;
  border: 1px solid rgba(113, 201, 255, 0.16);
  border-radius: 12px;
  background: rgba(2, 9, 17, 0.32);
}

.variable-transaction-row {
  display: grid;
  grid-template-columns:
    minmax(150px, 1.25fr) minmax(90px, 0.75fr)
    minmax(118px, 0.9fr);
  align-items: center;
  gap: 12px;
  min-height: 45px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-soft);
}

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

.variable-transaction-header {
  min-height: 38px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  font-size: 0.78rem;
  font-weight: 800;
}

.variable-transaction-header > span:first-child {
  text-align: right;
}

.variable-transaction-header > span:nth-child(2) {
  text-align: center;
}

.variable-transaction-header > span:last-child {
  text-align: left;
}

.variable-transaction-amount,
.variable-transaction-date {
  direction: ltr;
  white-space: nowrap;
}

.variable-transaction-amount {
  color: var(--red);
  text-align: center;
}

.variable-transaction-date {
  color: #c8d7e6;
  text-align: left;
}

.variable-detail-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.variable-detail-input {
  width: 100%;
  min-width: 0;
  min-height: 43px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
  outline: none;
}

.variable-detail-input:focus-visible {
  border-color: var(--blue);
  outline: 2px solid rgba(113, 201, 255, 0.24);
  outline-offset: 2px;
}

.variable-expense-modal-overlay {
  position: fixed;
  z-index: 1400;
  inset: 0;
  display: grid;
  padding: 28px;
  place-items: center;
  overflow-y: auto;
  background: rgba(2, 8, 15, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.variable-expense-modal {
  display: grid;
  width: min(760px, calc(100vw - 56px));
  max-height: calc(100dvh - 56px);
  gap: 24px;
  padding: 30px;
  overflow-y: auto;
  border: 1px solid rgba(113, 201, 255, 0.24);
  border-radius: 24px;
  color: var(--text);
  background: linear-gradient(155deg, #14273d, #0d1b2c);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.5);
}

.variable-expense-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.variable-expense-modal-header > div {
  min-width: 0;
}

.variable-expense-modal-header h3 {
  margin: 3px 0 5px;
  font-size: 1.55rem;
}

.variable-expense-modal-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.87rem;
}

.variable-expense-modal-kicker {
  color: #ff929c;
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.variable-expense-modal-close {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 116, 127, 0.38);
  border-radius: 11px;
  color: #ff929c;
  background: rgba(255, 116, 127, 0.08);
  cursor: pointer;
  font-size: 1.45rem;
}

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

.variable-expense-form-field {
  display: grid;
  gap: 8px;
  color: #c8d7e6;
  font-size: 0.92rem;
  font-weight: 700;
}

.variable-expense-form-field.description-field,
.variable-expense-form-field.subcategory-field {
  grid-column: 1 / -1;
}

.variable-expense-form-input {
  width: 100%;
  min-height: 52px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: #f4f8fc;
  background: rgba(2, 9, 17, 0.48);
  outline: none;
  font-size: 1rem;
}

.variable-expense-form-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(113, 201, 255, 0.11);
}

.variable-category-field {
  position: relative;
  z-index: 8;
  align-content: start;
}

.variable-category-suggestions {
  position: static;
  display: grid;
  max-height: 230px;
  margin-top: 4px;
  padding: 6px;
  overflow-y: auto;
  border: 1px solid rgba(113, 201, 255, 0.38);
  border-radius: 13px;
  background: #0b1929;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.42);
}

.variable-category-suggestion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 16px;
  min-height: 48px;
  padding: 10px 12px;
  border: 0;
  border-radius: 9px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  direction: rtl;
  text-align: right;
}

.variable-category-suggestion:hover,
.variable-category-suggestion.is-active {
  background: rgba(113, 201, 255, 0.13);
}

.variable-category-suggestion span {
  flex: 0 0 auto;
  margin-inline-start: auto;
  padding: 3px 8px;
  border-radius: 999px;
  direction: ltr;
  color: var(--red);
  background: rgba(255, 108, 122, 0.09);
  font-size: 0.84rem;
  white-space: nowrap;
}

.variable-category-suggestion strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variable-expense-form-input.is-preserved-budget {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  cursor: not-allowed;
}

.variable-expense-form-message {
  min-height: 22px;
  margin: -8px 0 0;
  color: var(--red);
  font-size: 0.88rem;
}

.variable-expense-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.variable-expense-modal-actions button {
  min-height: 46px;
  padding: 10px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
}

.variable-expense-modal-cancel {
  border: 1px solid var(--border);
  color: #d4e5f4;
  background: rgba(255, 255, 255, 0.045);
}

.variable-expense-modal-confirm {
  border-radius: 12px;
  border: 1px solid rgba(69, 241, 162, 0.55);
  color: #04120d;
  background: var(--green);
}

@media (min-width: 641px) {
  .variable-table .undo-column {
    width: 88px;
  }

  .variable-card .undo-heading,
  .variable-card .undo-cell {
    width: 88px;
  }

  .variable-details-row:hover {
    background: transparent;
  }

  /*
   * The selected expense and its open breakdown share one visual frame.
   * Borders are split between the two table rows so the result reads as
   * one expanded item instead of two separate cards.
   */
  .variable-main-row.is-details-open > td {
    border-top: 1px solid rgba(113, 201, 255, 0.58);
    border-bottom-color: transparent;
    background: rgba(113, 201, 255, 0.07);
  }

  .variable-main-row.is-details-open > td:first-child {
    border-inline-start: 1px solid rgba(113, 201, 255, 0.58);
  }

  .variable-main-row.is-details-open > td:last-child {
    border-inline-end: 1px solid rgba(113, 201, 255, 0.58);
  }

  .variable-main-row.is-details-open .variable-details-toggle.has-details {
    border-color: rgba(113, 201, 255, 0.95);
    background: rgba(113, 201, 255, 0.2);
    box-shadow: 0 0 13px rgba(113, 201, 255, 0.3);
  }

  .variable-details-row > td {
    padding: 0 16px;
    border-inline: 1px solid transparent;
    border-bottom: 1px solid transparent;
    background: transparent;
    box-shadow: none;
    transition:
      padding 280ms cubic-bezier(0.22, 1, 0.36, 1),
      border-color 220ms ease,
      background 220ms ease,
      box-shadow 220ms ease;
  }

  .variable-details-row.is-open > td {
    padding: 0 16px 16px;
    border-inline-color: rgba(113, 201, 255, 0.58);
    border-bottom-color: rgba(113, 201, 255, 0.58);
    background: rgba(113, 201, 255, 0.07);
    box-shadow: 0 13px 24px -17px rgba(113, 201, 255, 0.9);
  }

  .variable-details-panel {
    display: grid;
    width: 100%;
    max-height: 0;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 12px;
    padding: 0 6px;
    overflow: hidden;
    border: 0;
    border-top: 1px solid transparent;
    border-radius: 0;
    opacity: 0;
    background: transparent;
    transform: translateY(-8px);
    transform-origin: top;
    visibility: hidden;
    transition:
      max-height 320ms cubic-bezier(0.22, 1, 0.36, 1),
      padding 280ms cubic-bezier(0.22, 1, 0.36, 1),
      opacity 200ms ease,
      transform 280ms cubic-bezier(0.22, 1, 0.36, 1),
      border-color 220ms ease,
      visibility 0s linear 320ms;
  }

  .variable-details-row.is-open .variable-details-panel {
    max-height: var(--details-height, 800px);
    padding: 16px 6px 4px;
    border-top-color: rgba(113, 201, 255, 0.2);
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
    transition:
      max-height 320ms cubic-bezier(0.22, 1, 0.36, 1),
      padding 280ms cubic-bezier(0.22, 1, 0.36, 1),
      opacity 220ms ease 60ms,
      transform 280ms cubic-bezier(0.22, 1, 0.36, 1),
      border-color 220ms ease,
      visibility 0s linear;
  }

  .variable-details-heading {
    width: 100%;
    padding-inline: 4px;
    text-align: right;
  }

  .variable-details-heading strong {
    font-size: 1rem;
  }

  .variable-details-panel.has-transaction-breakdown {
    align-items: stretch;
  }

  .variable-details-panel .variable-transactions-breakdown {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .variable-expense-modal-overlay {
    align-items: start;
    padding: max(12px, env(safe-area-inset-top)) 10px
      max(12px, env(safe-area-inset-bottom));
  }

  .variable-expense-modal {
    width: 100%;
    max-height: calc(100dvh - 24px);
    gap: 20px;
    padding: 20px 16px;
    border-radius: 20px;
  }

  .variable-expense-modal-header {
    gap: 12px;
  }

  .variable-expense-modal-header h3 {
    overflow: hidden;
    font-size: 1.32rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .variable-expense-modal-header p {
    max-width: 230px;
    font-size: 0.78rem;
    line-height: 1.45;
  }

  .variable-expense-modal-close {
    width: 40px;
    height: 40px;
  }

  .variable-expense-form-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .variable-expense-form-field.description-field,
  .variable-expense-form-field.subcategory-field {
    grid-column: auto;
  }

  .variable-expense-form-input {
    min-height: 50px;
    font-size: 16px;
  }

  .variable-category-suggestions {
    max-height: 190px;
  }

  .variable-transaction-row {
    grid-template-columns:
      minmax(72px, 0.8fr) minmax(92px, 1fr)
      minmax(96px, 0.95fr);
    gap: 8px;
    padding-inline: 10px;
    font-size: 0.86rem;
  }

  .variable-transaction-header {
    font-size: 0.74rem;
  }

  .variable-expense-modal-actions {
    display: grid;
    grid-template-columns: 0.8fr 1.2fr;
    gap: 10px;
  }

  .variable-expense-modal-actions button {
    min-width: 0;
    padding-inline: 10px;
    font-size: 0.9rem;
  }

  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card) .variable-tools-cell {
    overflow: visible;
  }

  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card) .variable-row-tools {
    justify-content: flex-start;
    gap: 8px;
  }

  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card) .variable-details-toggle {
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card) .variable-details-chevron {
    width: 21px;
    height: 21px;
  }

  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card)
    tbody tr:not(.is-mobile-row-open) .variable-details-toggle {
    display: none;
  }

  /* Mobile details stay centered so the information feels like a focused dialog. */
  .variable-expense-modal-overlay:has(.mobile-details-modal) {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(14px, env(safe-area-inset-top)) 12px
      max(14px, env(safe-area-inset-bottom));
    overflow-y: auto;
    background: rgba(2, 8, 15, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .mobile-details-modal {
    position: relative;
    width: min(100%, 520px);
    max-height: min(84dvh, 680px);
    gap: 18px;
    padding: 26px 18px;
    border-radius: 24px;
    background: linear-gradient(180deg, #14283f 0%, #0d1b2c 100%);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.58);
    animation: mobile-details-sheet-in 180ms ease-out;
  }

  .mobile-details-modal::before {
    position: absolute;
    inset-block-start: 9px;
    inset-inline-start: 50%;
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.25);
    content: "";
    transform: translateX(-50%);
  }

  .mobile-details-modal .variable-expense-modal-kicker {
    color: var(--blue);
  }

  .mobile-details-modal .variable-expense-modal-header p {
    color: var(--red);
    font-size: 0.92rem;
    font-weight: 800;
  }

  .mobile-details-modal .mobile-details-fields {
    gap: 14px;
  }

  .mobile-details-modal.has-transaction-breakdown {
    max-height: min(82dvh, 680px);
  }

  .mobile-details-modal .variable-expense-modal-actions {
    position: sticky;
    bottom: 0;
    padding-top: 2px;
    background: linear-gradient(180deg, transparent, #0d1b2c 24%);
  }
}

/* Persistent amount history */
.amount-history-section {
  display: grid;
  gap: 9px;
  padding: 10px 12px 13px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(113, 201, 255, 0.025);
}

.amount-history-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

.amount-history-link {
  padding: 0;
  border: 0;
  color: #8fdbff;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  text-decoration: underline;
  text-decoration-color: rgba(143, 219, 255, 0.38);
  text-underline-offset: 4px;
}

.amount-history-link:hover,
.amount-history-link:focus-visible {
  color: #dff6ff;
  text-decoration-color: currentColor;
}

.amount-history-delete {
  color: #ff9da6;
  text-decoration-color: rgba(255, 157, 166, 0.38);
}

.amount-history {
  display: grid;
  overflow: hidden;
  border: 1px solid rgba(113, 201, 255, 0.13);
  border-radius: 10px;
  background: rgba(2, 9, 17, 0.34);
}

.amount-history[hidden] {
  display: none;
}

.amount-history-row {
  display: grid;
  direction: rtl;
  grid-template-columns: minmax(82px, 0.75fr) minmax(150px, 1.25fr) 74px 104px;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-soft);
  color: #cbd9e7;
  font-size: 0.78rem;
}

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

.amount-history-header {
  min-height: 34px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.032);
  font-size: 0.72rem;
  font-weight: 800;
}

.amount-history-row > :nth-child(2) {
  text-align: center;
}

.amount-history-row > :nth-child(3),
.amount-history-row > :nth-child(4) {
  text-align: left;
}

.amount-history-row.is-add strong {
  color: var(--green);
}

.amount-history-row.is-subtract strong,
.amount-history-row.is-direct strong {
  color: #ff929c;
}

.amount-history-empty {
  margin: 0;
  padding: 13px;
  color: var(--muted);
  text-align: center;
  font-size: 0.8rem;
}

.amount-history-deleted-notice {
  margin: 4px 12px 12px;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 11px;
  color: #aebdca;
  background: rgba(148, 163, 184, 0.055);
  font-size: 0.78rem;
  text-align: right;
}

.history-delete-dialog {
  display: grid;
  width: min(460px, calc(100vw - 28px));
  gap: 14px;
  padding: 24px;
  border: 1px solid rgba(255, 116, 127, 0.34);
  border-radius: 20px;
  color: var(--text);
  background: linear-gradient(155deg, #18283a, #0d1928);
  box-shadow: 0 28px 85px rgba(0, 0, 0, 0.58);
  animation: history-dialog-in 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.history-delete-dialog h3,
.history-delete-dialog p {
  margin: 0;
}

.history-delete-dialog p {
  color: #c5d3e0;
  line-height: 1.65;
}

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

.history-delete-actions button {
  min-height: 42px;
  padding: 9px 14px;
  border-radius: 11px;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.history-delete-cancel {
  border: 1px solid var(--border);
  color: #d7e4ef;
  background: rgba(255, 255, 255, 0.045);
}

.history-delete-confirm {
  border: 1px solid rgba(255, 116, 127, 0.62);
  color: #fff;
  background: rgba(199, 55, 72, 0.56);
}

@keyframes history-dialog-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* A single, gently animated confirmation replaces itself on rapid updates. */
.amount-update-toast {
  position: fixed;
  z-index: 3000;
  inset: 50% auto auto 50%;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  width: min(390px, calc(100vw - 32px));
  gap: 13px;
  padding: 16px 18px;
  border: 1px solid rgba(113, 201, 255, 0.34);
  border-radius: 20px;
  color: #edf9ff;
  background:
    radial-gradient(circle at 100% 0%, rgba(113, 201, 255, 0.16), transparent 48%),
    linear-gradient(145deg, rgba(19, 42, 63, 0.98), rgba(8, 22, 36, 0.99));
  box-shadow: 0 24px 74px rgba(0, 0, 0, 0.58), 0 0 0 1px rgba(255, 255, 255, 0.035) inset;
  backdrop-filter: blur(16px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.88);
  text-align: right;
  transition:
    opacity 300ms ease,
    visibility 300ms ease,
    transform 430ms cubic-bezier(0.16, 1, 0.3, 1);
}

.amount-update-toast.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.amount-update-toast.is-visible.is-add {
  border-color: rgba(69, 241, 162, 0.48);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.42), 0 0 24px rgba(69, 241, 162, 0.18);
}

.amount-update-toast.is-visible.is-subtract {
  border-color: rgba(255, 116, 127, 0.48);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.42), 0 0 24px rgba(255, 116, 127, 0.16);
}

.amount-update-toast.is-leaving {
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -50%) scale(0.94);
}

.amount-update-toast__icon {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid rgba(113, 201, 255, 0.36);
  border-radius: 15px;
  color: #bcecff;
  background: rgba(113, 201, 255, 0.12);
  box-shadow: 0 0 18px rgba(113, 201, 255, 0.12);
  font-size: 1.45rem;
  font-weight: 800;
}

.amount-update-toast.is-add .amount-update-toast__icon {
  border-color: rgba(69, 241, 162, 0.48);
  color: #8ff8c9;
  background: rgba(69, 241, 162, 0.13);
}

.amount-update-toast.is-subtract .amount-update-toast__icon {
  border-color: rgba(255, 116, 127, 0.48);
  color: #ff9da6;
  background: rgba(255, 116, 127, 0.13);
}

.amount-update-toast__content {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.amount-update-toast__title {
  color: #f4fbff;
  font-size: 0.98rem;
}

.amount-update-toast__message {
  color: #bdd0df;
  font-size: 0.83rem;
  line-height: 1.45;
}

@media (min-width: 641px) {
  .amount-cell .amount-editor,
  .budget-cell .amount-editor {
    display: grid;
    grid-template-columns: 14px minmax(72px, 86px) 28px 28px;
    width: 168px;
    margin-inline: auto;
    justify-content: start;
    gap: 4px;
  }

  .amount-cell .amount-input,
  .budget-cell .amount-input {
    width: 100%;
    min-width: 0;
    text-align: left;
  }

  .grouped-amount-display {
    width: 130px;
    margin-inline: auto;
  }
}

@media (max-width: 640px) {
  .amount-history-row {
    grid-template-columns:
      minmax(52px, 0.9fr) minmax(76px, 1.05fr)
      minmax(45px, 0.72fr) minmax(52px, 0.78fr);
    gap: 3px;
    padding: 6px 4px;
    font-size: 0.66rem;
  }

  .amount-history-header {
    font-size: 0.64rem;
  }

  .amount-history-row > * {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .history-delete-actions {
    display: grid;
    grid-template-columns: 0.8fr 1.2fr;
  }

  .amount-update-toast {
    width: calc(100vw - 36px);
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 11px;
    padding: 14px 15px;
    border-radius: 18px;
  }

  .amount-update-toast__icon {
    width: 42px;
    height: 42px;
    border-radius: 13px;
  }

  .amount-update-toast__message {
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .history-delete-dialog {
    animation: none;
    transition-duration: 0.01ms;
  }
}

@keyframes mobile-details-sheet-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.965);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}


/* Editable variable-expense breakdown */
.variable-transaction-row {
  grid-template-columns:
    minmax(150px, 1.25fr) minmax(90px, 0.72fr)
    minmax(132px, 0.9fr) minmax(72px, auto);
}

.variable-transaction-actions {
  display: flex;
  direction: ltr;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
}

.variable-transactions-edit-toggle,
.variable-transaction-delete,
.variable-transaction-save {
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 900;
  line-height: 1;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    background 150ms ease,
    box-shadow 150ms ease;
}

.variable-transactions-edit-toggle {
  justify-self: start;
  border: 1px solid rgba(113, 201, 255, 0.55);
  color: #9de3ff;
  background: rgba(113, 201, 255, 0.1);
}

.variable-transactions-edit-toggle:hover,
.variable-transactions-edit-toggle.is-active {
  border-color: rgba(113, 201, 255, 0.92);
  color: #e6f8ff;
  background: rgba(113, 201, 255, 0.2);
  box-shadow: 0 0 14px rgba(113, 201, 255, 0.25);
}

.variable-transaction-delete {
  border: 1px solid rgba(255, 116, 127, 0.5);
  color: #ff929c;
  background: rgba(255, 116, 127, 0.08);
}

.variable-transaction-delete:hover {
  border-color: rgba(255, 116, 127, 0.92);
  color: #fff;
  background: rgba(255, 116, 127, 0.2);
  box-shadow: 0 0 13px rgba(255, 116, 127, 0.22);
}

.variable-transaction-save {
  border: 1px solid rgba(69, 241, 162, 0.52);
  color: #68f3b4;
  background: rgba(69, 241, 162, 0.09);
}

.variable-transaction-save:hover {
  border-color: rgba(69, 241, 162, 0.9);
  color: #eafff5;
  background: rgba(69, 241, 162, 0.18);
  box-shadow: 0 0 13px rgba(69, 241, 162, 0.22);
}

.variable-transactions-edit-toggle:active,
.variable-transaction-delete:active,
.variable-transaction-save:active {
  transform: scale(0.9);
}

.variable-transaction-input {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 7px 9px;
  border: 1px solid rgba(113, 201, 255, 0.25);
  border-radius: 9px;
  color: var(--text);
  background: rgba(2, 9, 17, 0.46);
  outline: none;
  font: inherit;
}

.variable-transaction-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(113, 201, 255, 0.1);
}

.variable-transaction-amount-input {
  text-align: center;
}

.variable-transaction-date-input {
  direction: ltr;
  text-align: left;
}

.variable-add-transaction-btn {
  width: calc(100% - 24px);
  min-height: 44px;
  margin: 12px;
  border: 1px dashed rgba(69, 241, 162, 0.48);
  border-radius: 11px;
  color: #76f4ba;
  background: rgba(69, 241, 162, 0.055);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  transition:
    border-color 170ms ease,
    background 170ms ease,
    box-shadow 170ms ease,
    transform 170ms ease;
}

.variable-add-transaction-btn:hover {
  border-color: rgba(69, 241, 162, 0.86);
  background: rgba(69, 241, 162, 0.11);
  box-shadow: 0 0 16px rgba(69, 241, 162, 0.15);
  transform: translateY(-1px);
}

.variable-transactions-empty {
  margin: 0;
  padding: 18px 14px;
  color: var(--muted);
  text-align: center;
}

.is-new-transaction {
  background: rgba(69, 241, 162, 0.035);
}

@media (min-width: 641px) {
  .variable-main-row.is-details-open > td {
    border-top-color: rgba(113, 201, 255, 0.82);
    background: rgba(113, 201, 255, 0.105);
    box-shadow: inset 0 1px 0 rgba(193, 239, 255, 0.08);
  }

  .variable-details-row.is-open > td {
    border-inline-color: rgba(113, 201, 255, 0.82);
    border-bottom-color: rgba(113, 201, 255, 0.82);
    background: rgba(113, 201, 255, 0.105);
    box-shadow:
      0 18px 32px -18px rgba(113, 201, 255, 0.95),
      inset 0 -1px 0 rgba(193, 239, 255, 0.08);
  }

  .variable-details-panel {
    transform: translateY(-18px) scaleY(0.96);
    transition:
      max-height 430ms cubic-bezier(0.16, 1, 0.3, 1),
      padding 380ms cubic-bezier(0.16, 1, 0.3, 1),
      opacity 260ms ease,
      transform 400ms cubic-bezier(0.16, 1, 0.3, 1),
      border-color 260ms ease,
      visibility 0s linear 430ms;
  }

  .variable-details-row.is-open .variable-details-panel {
    transform: translateY(0) scaleY(1);
    animation: variable-details-settle 520ms cubic-bezier(0.16, 1, 0.3, 1);
    transition:
      max-height 430ms cubic-bezier(0.16, 1, 0.3, 1),
      padding 380ms cubic-bezier(0.16, 1, 0.3, 1),
      opacity 280ms ease 65ms,
      transform 400ms cubic-bezier(0.16, 1, 0.3, 1),
      border-color 260ms ease,
      visibility 0s linear;
  }
}

@keyframes variable-details-settle {
  0% {
    filter: brightness(0.78);
    opacity: 0;
  }
  55% {
    filter: brightness(1.14);
  }
  100% {
    filter: brightness(1);
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .variable-transaction-row {
    grid-template-columns:
      minmax(74px, 1fr) minmax(72px, 0.8fr)
      minmax(100px, 1fr) auto;
    gap: 6px;
    padding-inline: 8px;
  }

  .variable-transactions-edit-toggle,
  .variable-transaction-delete,
  .variable-transaction-save {
    width: 36px;
    height: 36px;
  }

  .variable-transaction-actions {
    gap: 4px;
  }

  .variable-transaction-input {
    min-height: 42px;
    padding-inline: 6px;
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .variable-details-row.is-open .variable-details-panel {
    animation: none;
  }
}


.variable-transaction-header > span:nth-child(3) {
  text-align: left;
}

.variable-transaction-header .variable-transactions-edit-toggle {
  align-self: center;
  justify-self: end;
}


/* Smooth transition between detail view and the unified editor */
.variable-transactions-breakdown {
  transform-origin: top center;
  animation: variable-editor-swap 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

.variable-transactions-breakdown.is-editing {
  animation-name: variable-editor-open;
  animation-duration: 360ms;
}

.variable-details-info {
  display: block;
  font-size: 1.05rem;
  font-weight: 950;
  line-height: 1;
}

@keyframes variable-editor-swap {
  from {
    opacity: 0.45;
    transform: translateY(-5px) scale(0.992);
    filter: brightness(0.88);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: brightness(1);
  }
}

@keyframes variable-editor-open {
  0% {
    opacity: 0.35;
    transform: translateY(-7px) scale(0.985);
    filter: brightness(0.82);
  }
  60% {
    opacity: 1;
    filter: brightness(1.08);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: brightness(1);
  }
}

@media (max-width: 640px) {
  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card) .variable-details-info {
    font-size: 1.2rem;
  }

  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card)
    .variable-details-toggle.is-open {
    border-color: rgba(113, 201, 255, 0.82);
    color: #dff6ff;
    background: rgba(113, 201, 255, 0.16);
  }
}

@media (prefers-reduced-motion: reduce) {
  .variable-transactions-breakdown,
  .variable-transactions-breakdown.is-editing {
    animation: none;
  }
}


/* Main amount becomes read-only information when it has multiple detail rows */
.grouped-amount-display {
  display: block;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: 36px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  color: var(--red);
  background: none;
  box-shadow: none;
  cursor: pointer;
  direction: ltr;
  text-align: left;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
}

.grouped-amount-display.positive {
  color: var(--green);
}

.grouped-amount-display.positive:hover,
.grouped-amount-display.positive:focus-visible {
  color: #86f8c4;
}

.variable-transactions-edit-toggle.has-unsaved-changes,
.variable-transactions-breakdown.has-unsaved-changes
  .variable-transactions-edit-toggle.is-active {
  border-color: #c8efff;
  background: rgba(113, 201, 255, 0.3);
  animation: details-save-pulse 1.05s ease-in-out infinite !important;
}

.variable-transactions-breakdown.is-save-settling {
  animation: details-save-settle 520ms cubic-bezier(0.16, 1, 0.3, 1);
}

.amount-cell.is-amount-updated {
  animation: details-amount-confirm 500ms ease-out;
}

@keyframes details-save-pulse {
  0%, 100% {
    box-shadow: 0 0 8px rgba(113, 201, 255, 0.2);
    transform: scale(1);
  }
  50% {
    border-color: #c8efff;
    box-shadow: 0 0 19px rgba(113, 201, 255, 0.68);
    transform: scale(1.065);
  }
}

@keyframes details-save-settle {
  0% {
    opacity: 0.72;
    transform: translateY(-3px) scale(0.994);
  }
  55% {
    border-color: rgba(69, 241, 162, 0.62);
    box-shadow: 0 0 18px rgba(69, 241, 162, 0.18);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes details-amount-confirm {
  0%, 100% { filter: brightness(1); }
  45% { filter: brightness(1.45); }
}

.income-card .variable-transaction-amount {
  color: var(--green);
}

:is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card) .variable-tools-cell {
  overflow: visible;
}

@media (max-width: 640px) {
  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card) .variable-row-tools {
    justify-content: flex-start;
    gap: 8px;
  }

  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card) .variable-details-toggle {
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card)
    tbody tr:not(.is-mobile-row-open) .variable-details-toggle {
    display: none;
  }

  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card) .variable-details-info {
    font-size: 1.2rem;
  }

  .grouped-amount-display {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  .variable-transactions-breakdown.is-save-settling,
  .amount-cell.is-amount-updated {
    animation: none;
  }
}

.grouped-amount-display:hover,
.grouped-amount-display:focus-visible {
  color: #ff9aa3;
  background: none;
  box-shadow: none;
}

.grouped-amount-display.positive:hover,
.grouped-amount-display.positive:focus-visible {
  color: #86f8c4;
}

@media (min-width: 641px) {
  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card) .undo-heading,
  :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card) .undo-cell {
    width: 88px;
  }
}

.grouped-amount-display:focus-visible {
  border-radius: 7px;
  outline: 2px solid rgba(113, 201, 255, 0.34);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .grouped-amount-display {
    text-align: left;
  }
}


@media (max-width: 640px) {
  .mobile-row-editing-ready
    :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card)
    tbody
    tr.is-mobile-row-open
    .amount-cell {
    display: grid;
    width: 100%;
    min-width: 0;
    height: auto;
    justify-self: stretch;
  }

  .mobile-row-editing-ready
    :is(.income-card, .fixed-card, .variable-card, .savings-card, .investments-card)
    tbody
    tr.is-mobile-row-open
    .grouped-amount-display {
    width: 100%;
    min-height: 48px;
    padding: 12px 10px;
    text-align: left;
  }

  .income-card .grouped-amount-display {
    color: var(--green);
  }
}

/* Final layout guards: keep all amount controls on one shared column line. */
.grouped-amount-editor {
  cursor: pointer;
}

.grouped-amount-editor .grouped-amount-input {
  border-color: rgba(113, 201, 255, 0.12);
  background: rgba(255, 255, 255, 0.025);
  pointer-events: none;
}

.grouped-amount-editor.negative .grouped-amount-input {
  color: var(--red);
}

.grouped-amount-editor.positive .grouped-amount-input {
  color: var(--green);
}

.grouped-amount-editor.savings-color .grouped-amount-input {
  color: #c89bff;
}

.grouped-amount-editor .grouped-amount-control {
  opacity: 0.28;
  cursor: not-allowed;
  pointer-events: none;
}

.grouped-amount-editor:hover .grouped-amount-input,
.grouped-amount-editor:focus-visible .grouped-amount-input {
  border-color: rgba(113, 201, 255, 0.3);
  background: rgba(113, 201, 255, 0.055);
}

@media (min-width: 641px) {
  .amount-cell .amount-editor,
  .budget-cell .amount-editor {
    display: grid;
    grid-template-columns: 14px minmax(72px, 86px) 28px 28px;
    width: 168px;
    margin-inline: auto;
    justify-content: start;
    gap: 4px;
  }

  .amount-cell .amount-input,
  .budget-cell .amount-input {
    width: 100%;
    min-width: 0;
    text-align: left;
  }

  .amount-cell .grouped-amount-display {
    width: 130px;
    margin-inline: auto;
  }
}

@media (max-width: 640px) {
  .grouped-amount-editor {
    width: 100%;
  }

  .variable-expense-modal-overlay:has(.mobile-details-modal) {
    align-items: center;
    padding: max(14px, env(safe-area-inset-top)) 12px
      max(14px, env(safe-area-inset-bottom));
  }

  .mobile-details-modal {
    width: min(100%, 520px);
    border-radius: 24px;
  }
}

/* Detail rows scroll independently while the header and add action stay visible. */
.variable-transaction-list {
  display: grid;
  min-width: 0;
}

.variable-transaction-list.is-scrollable {
  max-height: 354px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(125, 211, 252, 0.72) rgba(255, 255, 255, 0.055);
  scrollbar-width: thin;
}

.variable-transaction-list.is-scrollable::-webkit-scrollbar {
  width: 9px;
}

.variable-transaction-list.is-scrollable::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.045);
}

.variable-transaction-list.is-scrollable::-webkit-scrollbar-thumb {
  border: 2px solid rgba(5, 14, 27, 0.72);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(125, 211, 252, 0.9), rgba(69, 241, 162, 0.72));
}

.variable-transactions-breakdown.is-editing > .variable-add-transaction-btn {
  position: relative;
  z-index: 1;
  margin-block: 10px;
}

@media (max-width: 640px) {
  .variable-transaction-list.is-scrollable {
    max-height: min(48dvh, 390px);
  }

  .variable-transaction-list.is-scrollable::-webkit-scrollbar {
    width: 7px;
  }
}



/* Live search inside every detail table. */
.variable-detail-search {
  display: flex;
  direction: rtl;
  align-items: center;
  gap: 8px;
  margin: 10px 12px 0;
}

.variable-detail-search input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid rgba(113, 201, 255, 0.24);
  border-radius: 11px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  outline: none;
  font: inherit;
}

.variable-detail-search input::-webkit-search-cancel-button {
  display: none;
}

.variable-detail-search input:focus {
  border-color: rgba(113, 201, 255, 0.72);
  box-shadow: 0 0 0 3px rgba(113, 201, 255, 0.11);
}

.variable-detail-search button {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 116, 127, 0.34);
  border-radius: 11px;
  color: #ff929c;
  background: rgba(255, 116, 127, 0.08);
  cursor: pointer;
  font: inherit;
  font-size: 1.25rem;
  font-weight: 800;
}

.variable-detail-search button:hover {
  border-color: rgba(255, 116, 127, 0.68);
  background: rgba(255, 116, 127, 0.15);
}

.variable-detail-search button[hidden] {
  display: none;
}

.variable-detail-search-empty {
  border-bottom: 0;
}

.variable-transaction-row[hidden],
.amount-history-section[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  .variable-detail-search {
    margin: 9px 8px 0;
  }

  .variable-detail-search input {
    min-height: 44px;
    font-size: 16px;
  }

  .variable-detail-search button {
    flex-basis: 44px;
    width: 44px;
    height: 44px;
  }
}


.variable-detail-sort {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr);
  align-items: center;
  gap: 10px;
  margin: 9px 12px 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.variable-detail-sort select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid rgba(113, 201, 255, 0.24);
  border-radius: 11px;
  color: var(--text);
  background: #102238;
  outline: none;
  cursor: pointer;
  font: inherit;
}

.variable-detail-sort select:focus {
  border-color: rgba(113, 201, 255, 0.72);
  box-shadow: 0 0 0 3px rgba(113, 201, 255, 0.11);
}

@media (max-width: 640px) {
  .variable-detail-sort {
    grid-template-columns: 1fr;
    gap: 5px;
    margin: 8px 8px 0;
  }

  .variable-detail-sort select {
    min-height: 44px;
    font-size: 16px;
  }
}


