/* css/category-items.css */

/* --- 1. QUICK ADD SCROLLER --- */
.quick-add-scroll-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0;
}

.quick-add-scroll {
  display: flex;
  gap: 0.5rem;
  padding: 0 0 1rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
  cursor: grab;
  user-select: none;
}

.quick-add-scroll.dragging { cursor: grabbing; }

.quick-add-scroll::-webkit-scrollbar { height: 4px; }

.quick-add-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.scroll-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-60%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: all 0.2s ease;
  opacity: 0;
  pointer-events: none;
}

.quick-add-scroll-wrapper:hover .scroll-arrow,
.scroll-arrow.visible {
  opacity: 1;
  pointer-events: auto;
}

.scroll-arrow:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.scroll-arrow.left { left: -4px; }
.scroll-arrow.right { right: -4px; }

.quick-add-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 500;
  text-align: center;
  flex: 0 0 auto;
  scroll-snap-align: start;
  min-width: 80px;
}

.quick-add-btn:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--surface-hover);
}

.quick-add-icon {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

/* --- 2. CATEGORY ITEMS --- */
.category-item {
  display: flex;
  align-items: stretch;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.75rem;
  transition: all 0.25s ease;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}

.category-item:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.category-icon-box {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-radius: 10px;
  border: 2px solid transparent;
  flex-shrink: 0;
  transition: border-color 0.3s ease;

  /* --- NEW ALIGNMENT --- */
  align-self: flex-start; /* Anchors the box to the top instead of the middle */
  margin-top: 0.75rem;    /* Pushes it down exactly to the height of the text */
  margin-left: 1rem;      /* Keeps the breathing room on the left */
}

.icon-safe { border-color: var(--green); }
.icon-warn { border-color: #f59e0b; }
.icon-danger { border-color: var(--red); }
.icon-critical {
  border-color: var(--red);
  animation: iconPulse 1.5s infinite;
}

@keyframes iconPulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.category-body {
  flex: 1;
  padding: 1rem;
  min-width: 0;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.category-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.category-name-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem 1rem;
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}

.stat-label {
  color: var(--text-dim);
  font-weight: 500;
}

.stat-value {
  color: var(--text);
  font-weight: 600;
  text-align: right;
}

/* --- 3. BUDGET PROGRESS BARS --- */
.budget-bar-container {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 0.25rem;
}

.budget-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease;
}

.budget-safe { background-color: var(--green); }
.budget-warn { background-color: #f59e0b; }
.budget-danger { background-color: var(--red); }
.budget-critical {
  background-color: var(--red);
  animation: budgetPulse 1.5s infinite;
}

@keyframes budgetPulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.category-status {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-align: right;
  margin-top: 0.35rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-safe { color: var(--green); }
.status-warn { color: #f59e0b; }
.status-danger { color: var(--red); }
.status-critical { color: var(--red); animation: statusFlicker 1.5s infinite; }

@keyframes statusFlicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.no-budget-badge {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-style: italic;
  padding: 0.15rem 0.5rem;
  background: var(--surface-hover);
  border-radius: 4px;
  margin-top: 0.5rem;
  display: inline-block;
}

.category-delete-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.85rem;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
  line-height: 1;
}

.category-item:hover .category-delete-btn { opacity: 1; }

.category-delete-btn:hover {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  transform: scale(1.1);
}

/* --- 4. SORT CONTROL BAR --- */
.sort-control-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  padding: 0.5rem 1.5rem 0.5rem 0;
  border-bottom: 1px solid var(--border);
  margin: 0 1.5rem;
}

.sort-cat-count {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
  margin-right: auto;
  white-space: nowrap;
}

.sort-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.sort-dropdown-wrapper {
  position: relative;
}

.sort-select {
  padding: 0.25rem 1.4rem 0.25rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.2s;
  min-width: 110px;
}

.sort-select:hover { border-color: var(--accent); }

.sort-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(139, 92, 247, 0.15);
}

.sort-select option {
  background: var(--surface);
  color: var(--text);
}

.sort-arrow {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 0.6rem;
  color: var(--text-dim);
}

/* --- ADD FORM SPECIFICS --- */
.add-form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.reset-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  transition: color 0.2s;
}

.reset-btn:hover {
  color: var(--text);
}

.tag-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag-pill {
  padding: 0.4rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.tag-pill:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tag-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Numpad */
.compact-numpad {
  display: none; /* Hidden by default, JS toggles this */
  margin-top: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
}

.numpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.numpad-btn {
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.numpad-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.numpad-dot {
  grid-column: span 1;
}

.numpad-del {
  color: var(--red);
}

/* Notes Toggle */
.notes-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  cursor: pointer;
  user-select: none;
}

.notes-toggle-label {
  font-size: 0.9rem;
  color: var(--text);
}

.notes-status-text {
  font-weight: 400;
  font-size: 0.75rem;
  margin-left: 0.35rem;
  opacity: 0.7;
}

.notes-toggle-icon {
  font-size: 0.8rem;
  transition: transform 0.2s;
}

.notes-container {
  display: none;
  border: 1px solid var(--accent);
  border-top: none;
  border-radius: 0 0 8px 8px;
  animation: notesExpand 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.notes-container.open { display: block; }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

.notes-textarea {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  resize: vertical;
  min-height: 80px;
  outline: none;
}

.notes-textarea:focus {
  border-color: var(--accent);
}

.notes-char-count {
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

.notes-char-count.warning { color: #f59e0b; }
.notes-char-count.danger { color: var(--red); }

/* --- INCOME / SAVINGS VIEWS --- */
.income-overview-panel {
  border: none;
  box-shadow: none;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.income-overview-header {
  padding: 1.5rem 1.5rem 0.5rem;
}

.income-overview-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.income-subtitle {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

.income-breakdown-container {
  padding: 1.5rem;
  min-height: 200px;
  flex: 1;
}

.income-breakdown {
  /* Content injected by JS */
}

/* Savings Specifics */
.savings-header {
  padding: 1.5rem 1.5rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 0.5rem;
}

.savings-total {
  text-align: right;
}

.savings-amount {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--green);
}

.savings-goal {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.savings-progress-bar {
  width: 100%;
  height: 12px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 0.25rem;
}

.savings-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), #16a34a);
  transition: width 0.5s ease;
}

.savings-percent {
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.savings-buckets-grid {
  padding: 0 1.5rem 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.savings-quick-add {
  background: var(--surface-hover);
  border-top: 1px solid var(--border);
  padding: 1.5rem;
}

.quick-add-label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-dim);
}

.quick-add-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.income-quick-btn {
  padding: 0.5rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.income-quick-btn:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

/* Debt List */
.debt-list {
  padding: 1.5rem;
  min-height: 200px;
}

/* Recent Transactions */
.recent-tx-list {
  /* Content injected by JS */
}

/* Empty States */
.empty-income-state {
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
}

.empty-income-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-income-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.empty-income-desc {
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.empty-income-action {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.empty-income-action:hover {
  opacity: 0.9;
}

.no-income-data {
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
}

.empty-folder-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  opacity: 0.6;

  animation: folderFloat 3s ease-in-out infinite;
  display: inline-block; /* Required for transform to work */
}

/* ============================================
   PRODUCTION FIXES (APPEND TO BOTTOM)
   ============================================ */

/* 1. ACCESSIBILITY - Focus States for Keyboard Users */
.quick-add-btn:focus-visible,
.category-item:focus-visible,
.category-delete-btn:focus-visible,
.sort-select:focus-visible,
.tag-pill:focus-visible,
.income-quick-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* 2. KEYBOARD ACCESSIBILITY - Delete Button */
.category-delete-btn:focus {
  opacity: 1;
}

/* 3. MOBILE RESPONSIVENESS */
@media (max-width: 768px) {
  .savings-buckets-grid {
    grid-template-columns: 1fr;
    padding: 0 1rem 1rem;
  }

  .sort-control-bar {
    flex-wrap: wrap;
    justify-content: center;
    margin: 0 1rem;
    gap: 0.5rem;
  }

  .quick-add-scroll {
    padding-bottom: 0.5rem;
  }

  .category-item {
    flex-direction: column;
  }

  .category-icon-box {
    width: 40px;
    height: 40px;
    margin-bottom: 0.5rem;
  }

  .category-body {
    padding: 0.75rem;
  }

  .drilldown-layout {
    flex-direction: column;
  }

  .drilldown-left {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

/* 4. TOUCH DEVICE OPTIMIZATIONS */
@media (hover: none) {
  .category-delete-btn {
    opacity: 1; /* Always show on touch devices */
  }

  .quick-add-scroll {
    cursor: pointer;
  }
}

/* 5. PRINT STYLES */
@media print {
  .quick-add-scroll-wrapper,
  .scroll-arrow,
  .category-delete-btn,
  .sort-control-bar {
    display: none !important;
  }

  .category-item {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

/* 6. REDUCE MOTION FOR ACCESSIBILITY */
@media (prefers-reduced-motion: reduce) {
  .category-item,
  .budget-bar-fill,
  .icon-critical,
  .status-critical,
  .notes-container {
    animation: none !important;
    transition: none !important;
  }
}

/* 7. HIGH CONTRAST MODE SUPPORT */
@media (prefers-contrast: high) {
  .category-item {
    border-width: 2px;
  }

  .tag-pill,
  .quick-add-btn,
  .income-quick-btn {
    border-width: 2px;
  }

  .budget-bar-container {
    border: 1px solid var(--text-dim);
  }
}

/* 8. DARK/LIGHT THEME FIXES FOR HARD-CODED COLORS */
/* Replace hard-coded #f59e0b with variable */
.icon-warn,
.budget-warn,
.status-warn,
.notes-char-count.warning {
  color: var(--yellow, #f59e0b);
  background-color: var(--yellow, #f59e0b);
}

/* Define yellow if not in variables.css */
:root {
  --yellow: #f59e0b;
  --yellow-bg: rgba(245, 158, 11, 0.1);
}

[data-theme="light"] {
  --yellow: #d97706;
  --yellow-bg: rgba(217, 119, 6, 0.1);
}

/* 9. SCROLLBAR POLYFILL FOR FIREFOX */
.quick-add-scroll,
.category-list,
.cmd-view,
.drilldown-view {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* 10. ANIMATION DEFINITIONS (Consolidated) */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 11. UTILITY CLASSES FOR SPACING */
.mt-sm { margin-top: var(--space-sm); }
.mb-sm { margin-bottom: var(--space-sm); }
.p-sm { padding: var(--space-sm); }
.hidden { display: none; }
.text-center { text-align: center; }

@keyframes folderFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
