/* =========================================================
   Reusable Components
   ========================================================= */

/* ── Card ── */
.card-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-color);
  padding: 20px;
}

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-color);
  transition: var(--transition-base);
  position: relative;
  overflow: hidden;
  opacity: 0;
  animation: fadeInUp 0.35s ease forwards;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
}
.stat-card.income::before  { background: var(--success); }
.stat-card.expense::before { background: var(--danger); }
.stat-card.balance::before { background: var(--primary); }
.stat-card.due::before     { background: var(--info); }
.stat-card.warning::before { background: var(--warning); }
/* .stat-card.warning::before { background: var(--warning); } */
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.stat-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.stat-card.income  .stat-icon { background: var(--success-soft); color: var(--success); }
.stat-card.expense .stat-icon { background: var(--danger-soft);  color: var(--danger);  }
.stat-card.balance .stat-icon { background: var(--primary-soft); color: var(--primary); }
.stat-card.due     .stat-icon { background: var(--warning-soft); color: var(--warning); }
.stat-card.warning .stat-icon { background: var(--warning-soft); color: var(--warning); }

.stat-body { flex: 1; display: flex; flex-direction: column; }
.stat-label { font-size: var(--font-size-sm); color: var(--text-muted); }
.stat-value {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--text-primary);
  display: block;
  line-height: 1.2;
}
.stat-change { font-size: var(--font-size-xs); margin-top: 2px; }
.stat-change.positive { color: var(--success); }
.stat-change.negative { color: var(--danger); }

/* ── Buttons ── */
.btn { position: relative; overflow: hidden; font-weight: 500; transition: var(--transition-fast); border-radius: var(--radius-md); }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); color: #fff; }
.btn-ghost-primary { background: var(--primary-soft); color: var(--primary); border: 1px solid transparent; }
.btn-ghost-primary:hover { background: var(--primary); color: #fff; }
.btn-ghost-secondary { background: var(--bg-hover); color: var(--text-secondary); border: 1px solid var(--border-color); }
.btn-ghost-secondary:hover { background: var(--border-color); color: var(--text-primary); }
.btn-icon {
  width: 36px; height: 36px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
}

.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  transform: scale(0);
  animation: ripple 0.55s linear;
  pointer-events: none;
}
@keyframes ripple {
  to { transform: scale(4); opacity: 0; }
}

/* ── Table ── */
.table-wrapper {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
}
.table-search {
  position: relative; flex: 1; max-width: 320px;
  display: flex; align-items: center; gap: 8px;
}
.table-search i {
  position: absolute; left: 12px;
  color: var(--text-muted);
}
.table-search .form-control { padding-left: 32px; }
.table-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Force Bootstrap table vars to follow theme (fixes dark-mode white tbody). */
.table, .app-table {
  --bs-table-bg:         transparent;
  --bs-table-color:      var(--text-primary);
  --bs-table-border-color: var(--border-color);
  --bs-table-striped-bg: var(--bg-hover);
  --bs-table-hover-bg:   var(--bg-hover);
  --bs-table-hover-color:var(--text-primary);
  color: var(--text-primary);
}
.table > :not(caption) > * > *,
.app-table > :not(caption) > * > * {
  background-color: transparent;
  color: var(--text-primary);
  border-bottom-color: var(--border-color);
}

.app-table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
}
.app-table thead th {
  background: var(--bg-hover);
  color: var(--text-muted);
  font-weight: 600;
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  position: sticky; top: 0;
}
.app-table thead th:first-child { text-align: left; }
.app-table thead th.sortable { cursor: pointer; user-select: none; }
.app-table thead th.sortable:hover { color: var(--primary); }
.sort-icon { font-size: 11px; opacity: 0.5; }
.app-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: left;
  font-size: var(--font-size-sm);
  text-align: left;
}
.app-table tbody td:not(:first-child) { text-align: left; }
.app-table tbody tr:hover { background: var(--bg-hover); }
.app-table tbody tr:last-child td { border-bottom: 0; }
.app-table .empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

.table-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-top: 1px solid var(--border-color);
  flex-wrap: wrap; gap: 10px;
}
.pagination-controls { display: flex; align-items: center; gap: 6px; }
.page-numbers { display: flex; gap: 4px; }
.page-numbers .page-num {
  min-width: 32px; height: 32px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: var(--font-size-xs);
  transition: var(--transition-fast);
}
.page-numbers .page-num:hover { background: var(--primary-soft); color: var(--primary); }
.page-numbers .page-num.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination-controls .page-prev,
.pagination-controls .page-next {
  min-width: 32px; height: 32px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: var(--font-size-xs);
  transition: var(--transition-fast);
}
.pagination-controls .page-prev:hover:not(:disabled),
.pagination-controls .page-next:hover:not(:disabled) { background: var(--primary-soft); color: var(--primary); }
.pagination-controls .page-prev:disabled,
.pagination-controls .page-next:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Badges ── */
.type-badge, .status-badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11px; font-weight: 600;
}
.type-badge.income  { background: var(--success-soft); color: var(--success); }
.type-badge.expense { background: var(--danger-soft);  color: var(--danger);  }
.type-badge.due     { background: var(--warning-soft); color: #856404;        }
.type-badge.payment { background: var(--primary-soft); color: var(--primary); }

/* Back-compat aliases (old classes from v1) */
.badge-type          { display: inline-flex; align-items: center; padding: 3px 10px;
                       border-radius: var(--radius-full); font-size: 11px; font-weight: 600; }
.badge-type.income   { background: var(--success-soft); color: var(--success); }
.badge-type.expense  { background: var(--danger-soft);  color: var(--danger);  }
.badge-type.due      { background: var(--warning-soft); color: #856404;        }
.badge-type.payment  { background: var(--primary-soft); color: var(--primary); }

.stat-grid { display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 16px; }
.stat      { background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
  padding: 16px; display: flex; align-items: center; gap: 14px; }
.stat .icon { width: 44px; height: 44px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center; font-size: 22px; color: #fff; flex-shrink: 0; }
.stat.income  .icon { background: var(--success); }
.stat.expense .icon { background: var(--danger); }
.stat.net     .icon { background: var(--primary); }
.stat.due     .icon { background: var(--warning); color: #333; }
.stat .label { font-size: 13px; color: var(--text-muted); }
.stat .value { font-size: 20px; font-weight: 700; color: var(--text-primary); }

.table-wrap { background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-card); }
.table-wrap .table { margin: 0; color: var(--text-primary); }
.table-wrap .table thead th { background: var(--bg-hover); color: var(--text-muted);
  font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--border-color); }
.table-wrap .table tbody td { vertical-align: middle; border-color: var(--border-color); color: var(--text-primary); }
.table-wrap .table tbody tr:hover { background: var(--bg-hover); }
.ledger-item { display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border-color); }
.ledger-item:last-child { border-bottom: 0; }
.ledger-item .meta { font-size: 12px; color: var(--text-muted); }
.status-badge.pending { background: var(--warning-soft); color: #856404; }
.status-badge.done    { background: var(--success-soft); color: var(--success); }
.status-badge.overdue { background: var(--danger-soft);  color: var(--danger);  }

/* ── Modal ── */
.app-modal {
  --bs-modal-bg: var(--bg-card);
  --bs-modal-color: var(--text-primary);
  --bs-modal-border-color: var(--border-color);
  --bs-modal-header-border-color: var(--border-color);
  --bs-modal-footer-border-color: var(--border-color);
}
.app-modal .modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
}
.app-modal .modal-header {
  border-bottom: 1px solid var(--border-color);
  padding: 18px 22px;
  display: flex; align-items: center; justify-content: space-between;
}
.app-modal .modal-title { font-weight: 700; margin: 0; }
.btn-close-custom {
  background: var(--bg-hover); border: 0;
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted); cursor: pointer;
  transition: var(--transition-fast);
}
.btn-close-custom:hover { background: var(--danger-soft); color: var(--danger); }
.app-modal .modal-body { padding: 22px; }
.app-modal .modal-footer {
  border-top: 1px solid var(--border-color);
  padding: 14px 22px;
  gap: 8px;
}
[data-theme="dark"] .app-modal .btn-close {
  filter: invert(1) grayscale(100%);
  opacity: 0.8;
}
[data-theme="dark"] .app-modal .btn-close:hover {
  opacity: 1;
}

/* ── Toasts ── */
#toastContainer, .toast-root {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
}
.app-toast {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 280px; max-width: 380px;
  transform: translateX(120%);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  color: var(--text-primary);
}
.app-toast.show { transform: translateX(0); }
.app-toast.toast-success { border-left: 4px solid var(--success); }
.app-toast.toast-error   { border-left: 4px solid var(--danger);  }
.app-toast.toast-warning { border-left: 4px solid var(--warning); }
.app-toast.toast-info    { border-left: 4px solid var(--info);    }
.toast-icon { font-size: 20px; }
.app-toast.toast-success .toast-icon { color: var(--success); }
.app-toast.toast-error   .toast-icon { color: var(--danger);  }
.app-toast.toast-warning .toast-icon { color: var(--warning); }
.app-toast.toast-info    .toast-icon { color: var(--info);    }
.toast-msg { flex: 1; font-size: var(--font-size-sm); }
.toast-close {
  background: transparent; border: 0; color: var(--text-muted); cursor: pointer;
  font-size: 18px; padding: 2px 6px;
}

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: var(--font-size-sm); font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.form-control, .form-select {
  background: var(--bg-input);
  border: 1.5px solid var(--border-input);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 9px 14px;
  font-size: var(--font-size-sm);
  transition: var(--transition-fast);
}
.form-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%),
    linear-gradient(to right, var(--bg-input), var(--bg-input));
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 13px) calc(50% - 3px),
    0 0;
  background-size: 5px 5px, 5px 5px, 100% 100%;
  background-repeat: no-repeat;
  padding-right: 38px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  outline: none;
  background: var(--bg-card);
}
.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-valid   { border-color: var(--success); }

/* Placeholder follows theme (fixes dark-mode hard-to-read placeholders). */
.form-control::placeholder,
.form-select::placeholder,
input::placeholder,
textarea::placeholder {
  color: var(--text-muted) !important;
  opacity: 0.75;
}
.input-wrapper { position: relative; display: flex; align-items: center; }
.input-prefix {
  position: absolute; left: 14px;
  color: var(--text-muted);
  font-weight: 600;
}
.form-control.with-prefix { padding-left: 32px; }

/* ── Skeleton ── */
.skeleton {
  background: linear-gradient(90deg, var(--border-color) 25%, var(--bg-hover) 50%, var(--border-color) 75%);
  background-size: 700px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--radius-sm);
}
.skeleton-line { height: 14px; border-radius: var(--radius-full); }
.skeleton-icon { width: 48px; height: 48px; border-radius: var(--radius-md); }
.skeleton-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg-card);
  padding: 20px; border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}
.skeleton-body { flex: 1; display: flex; flex-direction: column; gap: 8px; }

/* ── Alert ── */
.app-alert {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  margin-bottom: 14px;
  font-size: var(--font-size-sm);
}
.app-alert.alert-success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.app-alert.alert-warning { background: var(--warning-soft); color: #856404;         border-color: var(--warning); }
.app-alert.alert-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: var(--danger);  }
.app-alert.alert-info    { background: var(--info-soft);    color: var(--info);    border-color: var(--info);    }
.app-alert .alert-close {
  margin-left: auto; background: transparent; border: 0;
  color: inherit; cursor: pointer; font-size: 16px;
}

/* ── Progress ── */
.progress-wrapper { margin-bottom: 14px; }
.progress-label {
  display: flex; justify-content: space-between;
  font-size: var(--font-size-xs); color: var(--text-muted);
  margin-bottom: 4px;
}
.app-progress {
  height: 8px; background: var(--bg-hover);
  border-radius: var(--radius-full); overflow: hidden;
}
.app-progress .progress-bar { background: var(--primary); }

/* ── Tabs ── */
.app-tabs {
  display: flex; gap: 2px;
  background: var(--bg-hover);
  padding: 4px; border-radius: var(--radius-md);
  width: fit-content;
  margin-bottom: 14px;
}
.tab-btn {
  background: transparent; border: 0;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary); cursor: pointer;
  font-size: var(--font-size-sm); font-weight: 500;
  transition: var(--transition-fast);
}
.tab-btn.active { background: var(--bg-card); color: var(--primary); box-shadow: var(--shadow-sm); }

/* ── Dropdown ── */
.dropdown-menu {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
}
.dropdown-item { color: var(--text-primary); font-size: var(--font-size-sm); padding: 8px 14px; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--bg-hover); color: var(--primary); }
.dropdown-divider { border-color: var(--border-color); }

/* ── Notification list ── */
.notif-dropdown { min-width: 320px; max-width: 360px; max-height: 400px; overflow-y: auto; }
.notif-header {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}
.notif-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border-color);
  font-size: var(--font-size-sm);
}
.notif-item:last-child { border-bottom: 0; }

/* ── Contact card grid ── */
.contact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.contact-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow-card);
  transition: var(--transition-base);
}
.contact-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.contact-avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700; font-size: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  object-fit: cover; flex-shrink: 0;
}
.contact-body { flex: 1; min-width: 0; }
.contact-name { font-weight: 600; color: var(--text-primary); display: block; }
.contact-phone { font-size: var(--font-size-xs); color: var(--text-muted); }

/* ── Notebook entry ── */
.notebook-entry {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
}
.notebook-entry:last-child { border-bottom: 0; }
.entry-type-due     { color: var(--danger);  font-weight: 700; }
.entry-type-payment { color: var(--success); font-weight: 700; }
.entry-type-note    { color: var(--text-muted); }

/* ── Task list ── */
.task-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--border-color);
}
.task-row:last-child { border-bottom: 0; }
.task-row.done .title { text-decoration: line-through; color: var(--text-muted); }
.task-row.overdue .due { color: var(--danger); font-weight: 600; }
.task-row .title { flex: 1; }
.task-row .due { font-size: var(--font-size-xs); color: var(--text-muted); }

/* ── Misc ── */
.amount-in  { color: var(--success); font-weight: 600; }
.amount-out { color: var(--danger);  font-weight: 600; }
.filter-bar {
  display: grid; gap: 10px; margin-bottom: 14px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  align-items: end;
}
.filter-bar .search-input {
  max-width: 280px;
  min-width: 140px;
  width: 100%;
}
@media (max-width: 640px) {
  .filter-bar {
    grid-template-columns: 1fr;
  }
  .filter-bar .search-input {
    max-width: none;
  }
