/* 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);
}

/* Select triggers sit on a distinct control color so they don't blend into the
   page background, and lift slightly on hover. */
.select {
  background: var(--color-control);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.select:hover {
  border-color: var(--color-text-muted);
}

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

/* ── Custom dropdown menus (Alpine-driven selects) ── */
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-menu);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  max-height: 280px;
  overflow-y: auto;
  z-index: 60;
  box-shadow: var(--shadow-md);
  padding: 4px;
}

.dropdown-item {
  padding: 8px 10px;
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  background: var(--color-menu-item);
  display: flex;
  align-items: center;
  gap: 8px;
}

.dropdown-item + .dropdown-item {
  margin-top: 2px;
}

.dropdown-item:hover {
  background: var(--color-hover);
}

.dropdown-item.is-selected {
  border: 1px solid var(--color-primary);
}

.dropdown-group-label {
  padding: 6px 10px 4px;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.dropdown-group:first-child .dropdown-group-label {
  margin-top: 0;
}

.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;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: 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);
}

.summary-card .label .tooltip-icon {
  width: .85rem;
  height: .85rem;
  font-size: .6rem;
  margin-left: .25rem;
}

/* ── Projection pace pills ── */
.pace-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.pace-on {
  background: #e7f1ff;
  color: #1c4ca0;
}

.pace-ahead {
  background: #d4f4dd;
  color: #136c34;
}

.pace-behind {
  background: #fde2e2;
  color: #9a2020;
}

/* Pace +/- as colored text (no pill background) */
.pace-on-text {
  color: var(--color-text-muted);
}

.pace-ahead-text {
  color: #136c34;
}

.pace-behind-text {
  color: #9a2020;
}

/* ── 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-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;
}

/* Skeleton placeholder for data that loads in a background second request. */
.skel {
  display: inline-block;
  min-width: 3.5em;
  height: 0.9em;
  vertical-align: middle;
  border-radius: 4px;
  background: linear-gradient(90deg,
    var(--color-border) 25%,
    var(--color-surface) 50%,
    var(--color-border) 75%);
  background-size: 200% 100%;
  animation: skel-pulse 1.2s ease-in-out infinite;
}

.skel-block {
  display: block;
  width: 100%;
  height: 4.5rem;
}

@keyframes skel-pulse {
  to { background-position: -200% 0; }
}

@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;
}

/* Compact inline stat card (e.g. Categories tab avg/budget/status) */
.tab-stat-card {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  margin-bottom: 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  /* no overflow:hidden — it would clip the stat tooltips. Children are
     transparent so the rounded corners still read cleanly. */
}

.tab-stat {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: .5rem .9rem;
}

.tab-stat + .tab-stat {
  border-left: 1px solid var(--color-border);
}

.tab-stat-label {
  display: inline-flex;
  align-items: center;
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
}

.tab-stat-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: var(--text-base);
}

.tab-stat-label .tooltip-icon {
  width: .85rem;
  height: .85rem;
  font-size: .58rem;
  margin-left: .3rem;
}

/* Structured tooltip body: title + label/value rows + footnote */
.tooltip-stats {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  text-align: left;
}

.tooltip-title {
  font-weight: 600;
  font-size: .8rem;
  color: var(--color-text-muted);
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--color-border);
}

.tooltip-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.tooltip-row-label {
  color: var(--color-text-muted);
}

.tooltip-row-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.tooltip-note {
  margin-top: .15rem;
  font-size: .68rem;
  color: var(--color-text-muted);
  font-style: italic;
}

/* ── 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;
  }
}