/* components.css — buttons, modals, inputs, tables, badges, cards, progress, toasts */

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast), opacity var(--transition-fast);
  text-decoration: none;
  background: none;
  color: var(--color-text);
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

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

.btn-danger:hover:not(:disabled) {
  opacity: .85;
}

.btn-ghost {
  border-color: var(--color-border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--color-surface);
}

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: 0.8rem;
}

.btn-icon {
  padding: var(--space-2);
  line-height: 1;
}

/* ── Inputs ── */
.input,
.select,
textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  transition: border-color var(--transition-fast);
}

.input:focus,
.select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, .15);
}

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

.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  margin-bottom: var(--space-1);
  font-size: var(--text-sm);
  font-weight: 500;
}

.form-error {
  color: var(--color-danger);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

/* ── Cards ── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.summary-card {
  text-align: center;
}

.summary-card .value {
  font-size: var(--text-2xl);
  font-weight: 700;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.summary-card .label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

thead th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: 600;
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tr:hover td {
  background: var(--color-surface);
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-pending {
  background: #e9ecef;
  color: #495057;
}

.badge-review {
  background: #fff3cd;
  color: #856404;
}

.badge-transfer {
  background: #cfe2ff;
  color: #084298;
}

.badge-split {
  background: #e2d9f3;
  color: #5a189a;
}

.badge-auto {
  background: #d1ecf1;
  color: #0c5460;
}

.badge-uncategorized {
  background: #fff3cd;
  color: #856404;
}

.badge-archived {
  background: #f8d7da;
  color: #842029;
}

.badge-month {
  background: #fff0e6;
  color: #9a4e00;
}

.badge-liquid {
  background: #d0ebff;
  color: #1864ab;
}

.badge-investments {
  background: #fff3bf;
  color: #855e00;
}

.badge-retirement {
  background: #e5dbff;
  color: #5f3dc4;
}

.badge-total {
  background: #e9ecef;
  color: #495057;
}

/* ── Progress bar ── */
.progress-wrap {
  position: relative;
  height: 8px;
  background: var(--color-border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 4px;
  transition: width var(--transition-base);
}

.progress-ok {
  background: var(--color-budget-ok);
}

.progress-warn {
  background: var(--color-budget-warn);
}

.progress-over {
  background: var(--color-budget-over);
}

.progress-dark {
  background: #c1121f;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-4);
}

.modal {
  background: var(--color-surface-raised);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-8);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}

.modal-title {
  font-size: var(--text-xl);
  font-weight: 600;
  margin: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

/* ── Undo toast ── */
.toast {
  position: fixed;
  bottom: var(--space-8);
  left: 50%;
  transform: translateX(-50%);
  background: #212529;
  color: #f8f9fa;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-6);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-6);
  z-index: 2000;
  min-width: 320px;
  overflow: hidden;
}

.toast-msg {
  flex: 1;
  font-size: var(--text-sm);
}

.toast-undo {
  color: var(--color-success);
  font-weight: 600;
  cursor: pointer;
  background: none;
  border: none;
  font-size: var(--text-sm);
}

.toast-close {
  color: var(--color-text-muted);
  cursor: pointer;
  background: none;
  border: none;
  font-size: var(--text-lg);
}

.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  width: 100%;
  background: var(--color-success);
  transform-origin: left;
  animation: toastShrink 5s linear forwards;
}

@keyframes toastShrink {
  from {
    transform: scaleX(1);
  }

  to {
    transform: scaleX(0);
  }
}

/* ── Spinner ── */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--color-text-muted);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
}

.empty-state p {
  margin: 0;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

/* ── Drag handle ── */
.drag-handle {
  cursor: grab;
  color: var(--color-text-muted);
  padding: var(--space-2);
}

.drag-handle:active {
  cursor: grabbing;
}

/* ── Filters panel ── */
.filters-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
}

/* ── Nav/Header ── */
.app-header {
  background: var(--color-surface-raised);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-logo {
  font-weight: 700;
  font-size: var(--text-xl);
  color: var(--color-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.app-nav {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-6);
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
}

.nav-link {
  padding: var(--space-3) var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.nav-link:hover {
  color: var(--color-text);
  text-decoration: none;
}

.nav-link.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.nav-alert-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--color-danger);
  border-radius: 50%;
  margin-left: 4px;
  vertical-align: middle;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

@media (max-width: 640px) {
  .app-header {
    padding: 0 var(--space-4);
  }

  .app-nav {
    padding: 0 var(--space-4);
  }
}

/* ── Tooltip ── */
.tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: var(--color-border);
  color: var(--color-text-muted);
  font-size: .65rem;
  font-style: normal;
  font-weight: 700;
  cursor: help;
  flex-shrink: 0;
  margin-left: .3rem;
  line-height: 1;
}

.tooltip-text {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface-raised, #1e2235);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: .5rem .7rem;
  font-size: .75rem;
  line-height: 1.45;
  white-space: normal;
  width: 220px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
  transition: opacity .15s, visibility .15s;
  z-index: 100;
}

.tooltip:hover .tooltip-text {
  visibility: visible;
  opacity: 1;
}

/* ── Mobile Overrides ── */
@media (max-width: 640px) {
  .modal {
    padding: var(--space-4);
  }

  .split-row {
    display: flex !important;
    flex-wrap: wrap !important;
  }

  .split-row>* {
    flex: 1 1 auto;
  }
}