:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --success-color: #16a34a;
  --danger-color: #dc2626;
  --warning-color: #d97706;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
}

/* Dark mode colors - defaults to OS preference */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --gray-50: #0f172a;
    --gray-100: #1e293b;
    --gray-200: #334155;
    --gray-300: #475569;
    --gray-400: #64748b;
    --gray-500: #94a3b8;
    --gray-600: #cbd5e1;
    --gray-700: #e2e8f0;
    --gray-800: #f1f5f9;
    --gray-900: #f8fafc;
    --white: #1e293b;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
  }
}

/* Dark mode when explicitly set */
[data-theme="dark"] {
  --gray-50: #0f172a;
  --gray-100: #1e293b;
  --gray-200: #334155;
  --gray-300: #475569;
  --gray-400: #64748b;
  --gray-500: #94a3b8;
  --gray-600: #cbd5e1;
  --gray-700: #e2e8f0;
  --gray-800: #f1f5f9;
  --gray-900: #f8fafc;
  --white: #1e293b;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

/* Light mode when explicitly set (overrides OS preference) */
[data-theme="light"] {
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  line-height: 1.6;
  color: var(--gray-800);
  background-color: var(--gray-50);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* Header */
.header {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  gap: 1.5rem;
  width: 100%;
}

.header-content {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtitle {
  font-size: 1.125rem;
  color: var(--gray-600);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.loan-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  width: 100%;
  margin-top: 2rem;
}

.stat-card {
  background: linear-gradient(135deg, var(--gray-50) 0%, var(--white) 100%);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 120px;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card.highlight {
  background: linear-gradient(135deg, var(--primary-color) 0%, #3b82f6 100%);
  color: var(--white);
  border-color: var(--primary-color);
}

.stat-card h3 {
  font-size: 0.875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
  opacity: 0.8;
  align-self: flex-start;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 0;
  align-self: flex-end;
  line-height: 1.2;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Content */
.main-content {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-sm);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.section-header h2 {
  font-size: 1.875rem;
  font-weight: 600;
  color: var(--gray-900);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--primary-color);
  color: var(--white);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background-color: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--gray-200);
}

.btn-profile {
  background-color: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
  width: 2.5rem;
  height: 2.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.btn-profile:hover:not(:disabled) {
  background-color: var(--gray-200);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Payment List */
.payment-list {
  margin-bottom: 2rem;
}

.payment-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  transition: all 0.2s ease;
  cursor: pointer;
}

.payment-item:hover {
  background-color: var(--gray-50);
  border-color: var(--primary-color);
  transform: translateX(4px);
}

/* Action Buttons */
.btn-edit {
  background: #6b7280; /* Medium gray */
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 0.4rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.75rem;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-edit:hover {
  background: #4b5563;
  transform: scale(1.05);
}

.btn-delete {
  background: #dc2626; /* Medium red */
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 0.4rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.75rem;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-delete:hover {
  background: #b91c1c;
  transform: scale(1.05);
}

.actions-cell {
  text-align: center;
  width: 90px;
  padding: 0.5rem !important;
}

.actions-cell .button-group {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  height: 100%;
}

/* Delete Confirmation Modal */
.delete-info {
  background-color: var(--gray-50);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
  border: 1px solid var(--gray-200);
}

.delete-info p {
  margin: 0.5rem 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.delete-info p:last-child {
  margin-bottom: 0;
}

.delete-info span {
  font-family: ui-monospace, monospace;
  font-weight: 600;
  color: var(--gray-900);
}

.btn-danger {
  background-color: #dc2626;
  color: white;
  border: 1px solid #dc2626;
}

.btn-danger:hover {
  background-color: #b91c1c;
  border-color: #b91c1c;
}

.payment-due-date {
  font-weight: 600;
  color: var(--gray-900);
  min-width: 140px;
  font-size: 1rem;
}

.payment-details {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
}

.payment-paid-on {
  font-size: 0.875rem;
  color: var(--gray-600);
  font-weight: 400;
}

.payment-amount {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--success-color);
  font-variant-numeric: tabular-nums;
}

.payment-balance {
  font-size: 0.875rem;
  color: var(--gray-600);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.loading {
  text-align: center;
  padding: 3rem;
  color: var(--gray-500);
  font-style: italic;
}

.actions {
  text-align: center;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalSlideIn 0.3s ease;
}

.modal-content.large {
  max-width: min(95vw, 1200px);
  width: auto;
  min-width: 800px;
  max-height: min(90vh, 800px);
  height: auto;
}

.modal-content.large .modal-body {
  padding: 1rem;
  max-height: calc(min(90vh, 800px) - 140px); /* Account for header and footer */
  overflow-y: auto;
}

/* Bulk Payment Styles */
.bulk-payment-header {
  margin-bottom: 1.5rem;
}

.bulk-payment-header h4 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 0.5rem;
}

.bulk-payment-rows {
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.bulk-payment-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.2fr 1.5fr auto;
  gap: 0.75rem;
  align-items: end;
  padding: 0.75rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  background: var(--gray-50);
}

.bulk-payment-row .form-group {
  margin-bottom: 0;
}

.bulk-payment-row .form-group label {
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
}

.bulk-payment-row .form-group input,
.bulk-payment-row .form-group select {
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
}

.bulk-payment-row .input-group {
  position: relative;
}

.bulk-payment-row .input-prefix {
  position: absolute;
  left: 0.75rem;
  color: var(--gray-500);
  font-weight: 500;
  z-index: 1;
  line-height: 1;
  top: 50%;
  transform: translateY(-50%);
}

.bulk-payment-row .input-group input {
  padding-left: 2rem;
}

.bulk-payment-row .btn-delete-row {
  background: var(--danger-color);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  line-height: 1;
  transition: background-color 0.2s ease;
}

.bulk-payment-row .btn-delete-row:hover {
  background: #b91c1c;
}

.bulk-payment-row.bulk-row-sorting {
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.6), 0 0 40px rgba(59, 130, 246, 0.4);
  border-color: rgba(59, 130, 246, 0.8);
  background: var(--white);
  transition: box-shadow 0.3s ease, border-color 0.3s ease, background 0.3s ease;
  z-index: 1000;
  position: relative;
}

.bulk-payment-rows {
  position: relative;
  overflow-y: auto;
}

.bulk-payment-actions {
  display: flex;
  justify-content: center;
  padding-top: 1rem;
  border-top: 1px solid var(--gray-200);
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.export-btn {
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
}

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-900);
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-400);
  padding: 0.25rem;
  line-height: 1;
}

.close-btn:hover {
  color: var(--gray-600);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  max-height: calc(90vh - 140px); /* Account for header and footer */
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  padding: 1.5rem;
  border-top: 1px solid var(--gray-200);
  background-color: var(--gray-50);
}

/* Forms */
.form-group {
  margin-bottom: 1.5rem;
}

.payment-info {
  background-color: var(--gray-50);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1.5rem;
  border: 1px solid var(--gray-200);
}

.payment-info p {
  margin: 0.5rem 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.payment-info p:last-child {
  margin-bottom: 0;
}

.payment-info p strong {
  flex-shrink: 0;
  white-space: nowrap;
}

.payment-info span {
  font-family: ui-monospace, monospace;
  font-weight: 600;
  color: var(--gray-900);
  text-align: right;
  margin-left: auto;
  flex-shrink: 0;
  white-space: nowrap;
}

#additionalPrincipalDisplay {
  text-align: right !important;
  margin-left: auto !important;
}

.form-group label {
  display: block;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 0.5rem;
}

.form-group select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  background-color: var(--white);
  color: var(--gray-900);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group select:hover {
  border-color: var(--gray-400);
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-prefix {
  position: absolute;
  left: 1rem;
  color: var(--gray-500);
  font-weight: 500;
  z-index: 1;
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.875rem;
  transition: border-color 0.2s ease;
}

.input-group input {
  padding-left: 2rem;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.form-group input:disabled,
.form-group input.disabled-field {
  background-color: var(--gray-100);
  color: var(--gray-500);
  cursor: not-allowed;
  opacity: 0.7;
}

.form-group input:disabled:focus,
.form-group input.disabled-field:focus {
  border-color: var(--gray-300);
  box-shadow: none;
}

/* Remove number input arrows */
input[type="number"] {
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.form-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

/* Payment Detail Modal */
.payment-detail-modal {
  max-width: 600px !important;
  min-width: 500px;
}

.payment-date {
  font-size: 1rem;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background-color: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}

.payment-details-table {
  overflow: visible;
}

.payment-breakdown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.payment-breakdown-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-200);
  vertical-align: middle;
}

.payment-breakdown-table tbody tr:last-child td {
  border-bottom: none;
}

.detail-label {
  font-weight: 500;
  color: var(--gray-700);
  width: 60%;
  white-space: nowrap;
}

.detail-value {
  font-family: ui-monospace, monospace;
  font-weight: 600;
  color: var(--gray-900);
  text-align: right;
  width: 40%;
  white-space: nowrap;
  font-size: 0.95rem;
}

.detail-value.payment-received {
  color: var(--success-color);
  font-weight: 700;
}

.detail-value.remaining-balance {
  color: var(--warning-color);
  font-weight: 700;
}

.payment-breakdown-table tbody tr:hover {
  background-color: var(--gray-50);
}

/* Transaction Table */
.table-help-text {
  font-size: 0.875rem;
  color: var(--gray-600);
  text-align: center;
  margin-bottom: 1rem;
  padding: 0.5rem;
  background-color: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}
.transaction-table-container {
  overflow: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  max-height: min(70vh, 600px);
  min-height: 300px;
  position: relative;
}

.transaction-table-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.transaction-table-container::-webkit-scrollbar-track {
  background: var(--gray-100);
  border-radius: 4px;
}

.transaction-table-container::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 4px;
}

.transaction-table-container::-webkit-scrollbar-thumb:hover {
  background: var(--gray-400);
}

.transaction-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  min-width: 800px; /* Ensures horizontal scroll on narrow screens */
  table-layout: auto;
}

.transaction-table th,
.transaction-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

.transaction-table th:nth-child(3), /* Payment */
.transaction-table th:nth-child(4), /* Principal */
.transaction-table th:nth-child(5), /* Interest */
.transaction-table th:nth-child(6), /* Extra Principal */
.transaction-table th:nth-child(7), /* Balance */
.transaction-table td:nth-child(3),
.transaction-table td:nth-child(4),
.transaction-table td:nth-child(5),
.transaction-table td:nth-child(6),
.transaction-table td:nth-child(7) {
  text-align: right;
  font-family: ui-monospace, monospace;
  white-space: nowrap;
  min-width: 120px;
}

.transaction-table th:nth-child(1), /* Date */
.transaction-table td:nth-child(1) {
  min-width: 100px;
}

.transaction-table th:nth-child(2), /* Due Date */
.transaction-table td:nth-child(2) {
  min-width: 100px;
}

.transaction-table th:nth-child(8), /* Actions */
.transaction-table td:nth-child(8) {
  min-width: 100px;
  text-align: center;
}

.transaction-table th {
  background-color: var(--gray-50);
  font-weight: 600;
  color: var(--gray-700);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  z-index: 10;
}

.transaction-table tbody tr:hover {
  background-color: var(--gray-50);
}

.transaction-table tbody tr:last-child td {
  border-bottom: none;
}

/* Toast Notifications */
.toast {
  position: fixed;
  top: 2rem;
  right: 2rem;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--success-color);
  z-index: 1100;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  min-width: 300px;
  opacity: 0;
  visibility: hidden;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
  visibility: visible;
}

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

.toast.success {
  border-left-color: var(--success-color);
}

.toast-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
}

.toast-message {
  font-weight: 500;
  color: var(--gray-800);
}

.toast-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--gray-400);
  padding: 0;
  line-height: 1;
}

.toast-close:hover {
  color: var(--gray-600);
}

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }
  
  .header {
    padding: 1.5rem;
  }
  
  .header-top {
    margin-bottom: 1.5rem;
  }
  
  .header h1 {
    font-size: 2rem;
  }
  
  .loan-stats {
    grid-template-columns: 1fr;
  }
  
  .main-content {
    padding: 1.5rem;
  }
  
  .section-header {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }
  
  .payment-item {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  
  .payment-balance {
    text-align: left;
  }
  
  .payment-due-date {
    min-width: auto;
    font-size: 0.9rem;
  }
  
  .modal {
    padding: 1rem;
  }
  
  .modal-content {
    margin: 0;
    max-height: 95vh;
  }
  
  .modal-body {
    max-height: calc(95vh - 140px);
  }
  
  .modal-content.large {
    max-width: 95vw;
    min-width: unset;
    width: 95vw;
    max-height: 95vh;
  }
  
  .modal-content.large .modal-body {
    max-height: calc(95vh - 140px);
  }
  
  .transaction-table-container {
    max-height: min(60vh, 400px);
    min-height: 250px;
  }
  
  .modal-footer {
    flex-direction: column;
  }
  
  .transaction-table {
    font-size: 0.75rem;
    min-width: 600px; /* Reduced for mobile but still requires horizontal scroll */
  }
  
  .transaction-table th,
  .transaction-table td {
    padding: 0.5rem;
  }
  
  .transaction-table th:nth-child(3),
  .transaction-table th:nth-child(4),
  .transaction-table th:nth-child(5),
  .transaction-table th:nth-child(6),
  .transaction-table th:nth-child(7),
  .transaction-table td:nth-child(3),
  .transaction-table td:nth-child(4),
  .transaction-table td:nth-child(5),
  .transaction-table td:nth-child(6),
  .transaction-table td:nth-child(7) {
    min-width: 90px;
  }
  
  .actions-cell {
    width: 70px;
    padding: 0.25rem !important;
  }
  
  .button-group {
    gap: 0.25rem;
  }
  
  .btn-edit,
  .btn-delete {
    width: 24px;
    height: 24px;
    padding: 0.25rem;
    font-size: 0.7rem;
  }
}

/* Admin Page Styles */
.admin-section {
  max-width: 800px;
  margin: 0 auto;
}

.admin-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
}

.admin-card h2 {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 0.5rem;
}

.form-description {
  color: var(--gray-600);
  margin-bottom: 2rem;
  line-height: 1.6;
}

.warning-box {
  background-color: #fef3c7;
  border: 1px solid #fbbf24;
  border-left: 4px solid var(--warning-color);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
  color: var(--gray-800);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .warning-box {
    background-color: #451a03;
    border-color: #d97706;
    color: #fef3c7;
  }
}

[data-theme="dark"] .warning-box {
  background-color: #451a03;
  border-color: #d97706;
  color: #fef3c7;
}

.warning-box strong {
  color: var(--warning-color);
  font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .warning-box strong {
    color: #fbbf24;
  }
}

[data-theme="dark"] .warning-box strong {
  color: #fbbf24;
}

.delete-confirmation {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #fbbf24;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .delete-confirmation {
    border-top-color: #d97706;
  }
}

[data-theme="dark"] .delete-confirmation {
  border-top-color: #d97706;
}

.delete-confirmation label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--gray-800);
}

.delete-confirmation input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #fbbf24;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .delete-confirmation input {
    border-color: #d97706;
  }
}

[data-theme="dark"] .delete-confirmation input {
  border-color: #d97706;
}

.delete-confirmation input:focus {
  outline: none;
  border-color: var(--warning-color);
  box-shadow: 0 0 0 3px rgb(217 119 6 / 0.1);
}

.loan-form {
  margin-top: 1.5rem;
}

.form-preview {
  background: linear-gradient(135deg, var(--primary-color) 0%, #3b82f6 100%);
  color: var(--white);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 2rem 0;
  text-align: center;
}

.form-preview h3 {
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  opacity: 0.9;
}

.preview-value {
  font-size: 2rem;
  font-weight: 700;
  font-family: ui-monospace, monospace;
  margin: 0.5rem 0;
}

.form-preview .form-hint {
  color: rgba(255, 255, 255, 0.8);
  margin-top: 0.5rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--gray-200);
}

.form-actions .btn {
  min-width: 120px;
}

.input-suffix {
  position: absolute;
  right: 1rem;
  color: var(--gray-500);
  font-weight: 500;
  z-index: 1;
}

.input-group input[type="number"] {
  padding-right: 2.5rem;
}

/* Utility Classes */
.text-success { color: var(--success-color); }
.text-danger { color: var(--danger-color); }
.text-warning { color: var(--warning-color); }
.font-mono { font-family: ui-monospace, monospace; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Theme Toggle Button */
.theme-toggle {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background-color: var(--white);
  color: var(--gray-800);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  z-index: 1000;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-md);
}

.theme-toggle:active {
  transform: scale(0.95);
}

@media (max-width: 768px) {
  .theme-toggle {
    bottom: 1rem;
    right: 1rem;
    width: 44px;
    height: 44px;
    font-size: 1.25rem;
  }
}

/* Loan Cards for Admin Dashboard */
.loan-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  margin-bottom: 1.5rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.loan-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.loan-card-content {
  padding: 1.5rem;
}

.loan-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--gray-200);
}

.loan-card-header h3 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--gray-900);
  margin: 0;
}

.loan-card-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  padding: 0.5rem;
  border-radius: var(--radius);
  transition: background-color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background-color: var(--gray-100);
}

.delete-loan-btn:hover {
  background-color: #fee2e2;
}

.loan-card-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.loan-metric {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.metric-label {
  font-size: 0.875rem;
  color: var(--gray-600);
  font-weight: 500;
}

.metric-value {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-900);
}

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.empty-state h2 {
  font-size: 1.5rem;
  color: var(--gray-900);
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--gray-600);
  margin-bottom: 2rem;
}

.header-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-shrink: 0;
}

.btn-danger {
  background-color: var(--danger-color);
  color: var(--white);
}

.btn-danger:hover {
  background-color: #b91c1c;
}

@media (max-width: 400px) {
  .loan-card-body {
    grid-template-columns: 1fr;
  }

  .header-top {
    flex-wrap: wrap;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .header-actions .btn {
    flex: 0 1 auto;
  }

  .header-actions .btn-profile {
    flex-shrink: 0;
  }
}

/* Authentication Pages */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 2rem;
  background: var(--gray-50);
}

.auth-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: 100%;
  max-width: 450px;
}

.auth-card h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  color: var(--gray-900);
}

.auth-subtitle {
  color: var(--gray-600);
  margin-bottom: 2rem;
}

.oidc-providers {
    margin-bottom: 1.5rem;
}

.oidc-provider-btn {
    width: 100%;
    padding: 0.75rem 1.5rem;
    margin-bottom: 0.75rem;
    background-color: var(--white);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.oidc-provider-btn:hover {
    background-color: var(--gray-50);
    border-color: var(--gray-400);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.oidc-provider-btn:last-child {
    margin-bottom: 0;
}

.auth-divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
    color: var(--gray-500);
    font-size: 0.875rem;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--gray-300);
}

.auth-divider span {
    padding: 0 1rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Password Input Group */
.password-input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.password-input-group input {
  padding-right: 3rem;
  flex: 1;
}

.password-toggle {
  position: absolute;
  right: 0.75rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  font-size: 1.25rem;
  color: var(--gray-600);
  display: flex;
  align-items: center;
  justify-content: center;
}

.password-toggle:hover {
  color: var(--gray-900);
}

.password-strength {
  margin-top: 0.5rem;
  font-size: 0.875rem;
}

.password-strength.weak .strength-weak {
  color: var(--danger-color);
}

.password-strength.medium .strength-medium {
  color: var(--warning-color);
}

.password-strength.strong .strength-strong {
  color: var(--success-color);
}

.password-match {
  margin-top: 0.5rem;
  font-size: 0.875rem;
}

.password-match.valid .match-valid {
  color: var(--success-color);
}

.password-match.invalid .match-invalid {
  color: var(--danger-color);
}

.optional {
  color: var(--gray-500);
  font-weight: normal;
}

/* User Management */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.section-header h2 {
  font-size: 1.5rem;
  color: var(--gray-900);
}

.user-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  margin-bottom: 1rem;
  padding: 1.5rem;
  border: 1px solid var(--gray-200);
}

.user-card-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.user-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-card-header h3 {
  font-size: 1.25rem;
  margin: 0;
  color: var(--gray-900);
}

.role-badge {
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.role-badge.admin {
  background-color: #dbeafe;
  color: #1e40af;
}

[data-theme="dark"] .role-badge.admin {
  background-color: #1e3a8a;
  color: #bfdbfe;
}

.role-badge.user {
  background-color: #f3f4f6;
  color: var(--gray-700);
}

[data-theme="dark"] .role-badge.user {
  background-color: #374151;
  color: var(--gray-300);
}

.user-info {
  color: var(--gray-700);
  font-size: 0.875rem;
}

.user-card-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 400px;
  overflow-y: auto;
  padding: 1rem;
  background: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius);
  transition: background-color 0.2s;
}

.checkbox-label:hover {
  background-color: var(--gray-100);
}

.checkbox-label input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  cursor: pointer;
}

.checkbox-label span {
  flex: 1;
  color: var(--gray-900);
}

/* Profile Button */
#profileBtn {
  min-width: auto;
  padding: 0.5rem 0.75rem;
  font-size: 1.25rem;
  line-height: 1;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .auth-card {
    padding: 1.5rem;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .user-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .user-card-actions {
    width: 100%;
  }

  .user-card-actions .btn {
    flex: 1;
  }
}
