.loans-card {
  --loans-accent: #8b5cf6;
  --loans-accent-soft: rgba(139, 92, 246, 0.16);
  --accent: var(--loans-accent);
}

.loans-color {
  color: #dbe5f1;
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
}

.loans-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 0.72fr);
  gap: 10px;
  margin: 14px 0 12px;
}

.loans-toolbar[hidden],
.loans-table-wrap[hidden] {
  display: none !important;
}

.loans-search-field,
.loans-sort-field {
  min-width: 0;
}

.loans-search-field input,
.loans-sort-field select {
  width: 100%;
  height: 44px;
  min-height: 44px;
  box-sizing: border-box;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 12px;
  color: var(--text, #f8fafc);
  background: rgba(15, 23, 42, 0.72);
  padding: 0 12px;
  font: inherit;
  outline: none;
}

.loans-search-field input:focus,
.loans-sort-field select:focus {
  border-color: rgba(167, 139, 250, 0.72);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.14);
}

.loans-table-wrap {
  overflow-x: auto;
}

.loans-table {
  min-width: 690px;
}

.loan-name-cell {
  position: relative;
  min-width: 210px;
}

.loan-name {
  font-weight: 750;
  color: #f8fafc;
  overflow-wrap: anywhere;
}

.loan-progress-line {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
}

.loan-progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.22);
}

.loan-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #7c3aed, #a78bfa);
  transition: width 220ms ease;
}

.loan-progress-fill.is-complete {
  background: linear-gradient(90deg, #059669, #34d399);
}

.loan-progress-percent {
  min-width: 42px;
  color: #c4b5fd;
  font-size: 0.78rem;
  font-weight: 800;
  direction: ltr;
  text-align: left;
}

.loan-amount,
.loan-remaining {
  white-space: nowrap;
  font-weight: 700;
  text-align: center;
}

.loan-stat-label {
  display: none;
}

.loan-stat-value {
  direction: ltr;
  unicode-bidi: isolate;
}

.loan-remaining.is-complete {
  color: #34d399;
}

.loan-repaid-input {
  width: 94px;
  min-height: 38px;
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 10px;
  color: #f8fafc;
  background: rgba(15, 23, 42, 0.8);
  padding: 0 10px;
  font: inherit;
  font-weight: 750;
  direction: ltr;
  text-align: center;
  outline: none;
}

.loan-repaid-cell {
  text-align: center;
}

.loan-repaid-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  direction: ltr;
  font-weight: 700;
  white-space: nowrap;
}

.loan-repaid-currency {
  flex: 0 0 auto;
  line-height: 1;
}

.loan-repaid-input:focus {
  border-color: #a78bfa;
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.loan-delete-button {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(248, 113, 113, 0.38);
  border-radius: 10px;
  color: #fca5a5;
  background: rgba(127, 29, 29, 0.18);
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  font-weight: 900;
}

.loan-edit-button {
  display: none;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(96, 165, 250, 0.42);
  border-radius: 10px;
  color: #93c5fd;
  background: rgba(30, 64, 175, 0.18);
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  font-weight: 900;
}

.loan-delete-button:hover {
  color: #fff;
  background: rgba(220, 38, 38, 0.5);
}

.loans-empty-message {
  margin: 12px 0 0;
  color: #94a3b8;
  text-align: center;
}

.loans-empty-message:not(.hidden) + .add-row-btn {
  margin-top: 18px;
}

.loan-confetti {
  position: absolute;
  z-index: 5;
  inset: -12px 0 0;
  overflow: hidden;
  border-radius: 12px;
  pointer-events: none;
}

.loan-confetti-piece {
  position: absolute;
  top: -12px;
  left: var(--confetti-x);
  width: 7px;
  height: 11px;
  border-radius: 2px;
  background: var(--confetti-color);
  opacity: 0;
  animation: loan-confetti-fall var(--confetti-duration) cubic-bezier(0.2, 0.7, 0.3, 1)
    var(--confetti-delay) forwards;
}

@keyframes loan-confetti-fall {
  0% {
    opacity: 0;
    transform: translate3d(0, -8px, 0) rotate(0deg);
  }
  12% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--confetti-drift), 125px, 0)
      rotate(var(--confetti-rotation));
  }
}

.loan-dialog {
  width: min(440px, calc(100vw - 28px));
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 20px;
  color: #f8fafc;
  background: #0b1627;
  padding: 0;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.loan-dialog::backdrop {
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(4px);
}

.loan-dialog-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.loan-dialog-header h3 {
  margin: 0;
  font-size: 1.3rem;
}

.loan-dialog-header p {
  margin: 6px 0 0;
  color: #94a3b8;
  font-size: 0.9rem;
}

.loan-dialog-field {
  display: grid;
  gap: 7px;
  color: #cbd5e1;
  font-weight: 700;
}

.loan-dialog-field input {
  min-height: 44px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 12px;
  color: #f8fafc;
  background: rgba(15, 23, 42, 0.78);
  padding: 0 12px;
  font: inherit;
  outline: none;
}

.loan-dialog-field input:focus {
  border-color: #a78bfa;
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.loan-dialog-actions {
  display: flex;
  justify-content: flex-start;
  gap: 10px;
  margin-top: 4px;
}

.loan-dialog-actions button {
  min-height: 42px;
  border-radius: 11px;
  padding: 0 16px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.loan-dialog-save {
  border: 1px solid #8b5cf6;
  color: white;
  background: #7c3aed;
}

.loan-dialog-cancel {
  border: 1px solid rgba(148, 163, 184, 0.3);
  color: #cbd5e1;
  background: rgba(30, 41, 59, 0.72);
}

.loan-toast {
  position: fixed;
  z-index: 10000;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 18px);
  max-width: min(420px, calc(100vw - 28px));
  border: 1px solid rgba(52, 211, 153, 0.38);
  border-radius: 12px;
  color: #ecfdf5;
  background: rgba(6, 78, 59, 0.96);
  padding: 11px 16px;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transition: opacity 170ms ease, transform 170ms ease;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.35);
}

.loan-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.loan-toast.is-error {
  border-color: rgba(248, 113, 113, 0.45);
  color: #fff1f2;
  background: rgba(127, 29, 29, 0.97);
}

@media (max-width: 760px) {
  .loans-toolbar {
    grid-template-columns: 1fr;
  }

  .loans-table {
    min-width: 0;
  }

  .loans-table thead {
    display: none;
  }

  .loans-table,
  .loans-table tbody,
  .loans-table tr,
  .loans-table td {
    display: block;
    width: 100%;
  }

  .loans-table tr {
    position: relative;
    margin-bottom: 12px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 14px;
    padding: 18px 14px 14px;
    background: rgba(15, 23, 42, 0.46);
  }

  .loans-table td {
    border: 0;
    padding: 5px 0;
  }

  .loans-table td:not(.loan-name-cell):not(.loan-action-cell) {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 46px;
    padding: 8px 2px;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
  }

  .loan-stat-label {
    display: inline;
    color: #94a3b8;
    font-size: 0.82rem;
    font-weight: 700;
  }

  .loan-name-cell {
    min-width: 0;
    padding-left: 42px !important;
    margin-top: 12px;
    padding-bottom: 14px !important;
  }

  .loan-name {
    padding-inline-end: 2px;
    font-size: 1rem;
    line-height: 1.45;
  }

  .loan-action-cell {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex !important;
    width: auto !important;
    gap: 6px;
    direction: ltr;
    padding: 0 !important;
  }

  .loan-edit-button {
    display: inline-grid;
    place-items: center;
  }

  .loan-repaid-input[readonly] {
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
  }

  .is-loan-editing .loan-repaid-input {
    border-color: #a78bfa;
    background: rgba(15, 23, 42, 0.8);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
  }

  .loan-progress-line {
    margin: 14px 0 4px;
  }

  .loan-repaid-input {
    width: 100px;
  }

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

@media (prefers-reduced-motion: reduce) {
  .loan-confetti {
    display: none;
  }
}
