/* ============================================
   Expense Tracker - Stylesheet
   Theme: Quick Tools (primary #2DBAA3)
   ============================================ */

/* CSS Variables */
:root {
  --primary: #2DBAA3;
  --primary-hover: #25A08C;
  --primary-light: rgba(45, 186, 163, 0.12);
  --bg: #f5f7fa;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-secondary: #7f8c8d;
  --border: #e1e8ed;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --focus-ring: rgba(45, 186, 163, 0.28);
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --success: #27ae60;
  --warning: #f39c12;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --card-bg: #161b22;
  --text: #c9d1d9;
  --text-secondary: #8b949e;
  --border: #30363d;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.4);
  --focus-ring: rgba(45, 186, 163, 0.36);
  --primary-light: rgba(45, 186, 163, 0.18);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.3s, color 0.3s;
  padding-bottom: 72px; /* space for bottom nav */
}

/* Header */
header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  transition: background 0.3s, border-color 0.3s;
  position: sticky;
  top: 0;
  z-index: 50;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
}

.logo svg {
  width: 28px;
  height: 28px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.back-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.2s;
}

.theme-toggle:hover {
  border-color: var(--primary);
}

/* Main Content */
main {
  flex: 1;
  padding: 24px 32px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* View Sections */
.view-section {
  display: none;
  animation: fadeIn 0.3s ease;
}

.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Page Headers */
.dashboard-header,
.page-header {
  margin-bottom: 24px;
}

.dashboard-header h2,
.page-header h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: all 0.3s;
  text-align: center;
  cursor: pointer;
}

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

.stat-card.total {
  border-top: 3px solid var(--primary);
}

.stat-card.count {
  border-top: 3px solid #3498db;
}

.stat-card.avg {
  border-top: 3px solid var(--warning);
}

.stat-card.top {
  border-top: 3px solid var(--danger);
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.stat-card.total .stat-value {
  color: var(--primary);
}

/* Chart Cards */
.chart-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  transition: background 0.3s;
}

.chart-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.chart-wrapper {
  position: relative;
  height: 280px;
}

.chart-wrapper.doughnut {
  max-width: 360px;
  margin: 0 auto;
}

/* Form Cards */
.form-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  max-width: 560px;
  transition: background 0.3s;
}

.form-group {
  margin-bottom: 20px;
}

.form-group.inline {
  display: flex;
  gap: 12px;
  align-items: center;
}

.form-group.inline input[type="text"] {
  flex: 1;
}

.form-group.inline select {
  flex: 1;
  min-width: 120px;
}

/* Tags form rows - prevent button wrapping on narrow screens */
.tags-form-row {
  flex-wrap: nowrap;
}

@media (max-width: 768px) {
  .tags-form-row {
    flex-wrap: wrap;
  }
  .tags-form-row input[type="text"] {
    width: 100%;
    flex-basis: 100%;
  }
}

.form-group.inline input[type="color"] {
  width: 48px;
  height: 40px;
  padding: 2px;
  cursor: pointer;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.input-prefix {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-prefix:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.input-prefix .prefix {
  padding: 10px 12px;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.input-prefix input {
  border: none;
  box-shadow: none;
  border-radius: 0;
  flex: 1;
}

.input-prefix input:focus {
  box-shadow: none;
}

/* Buttons */
.btn-primary {
  padding: 12px 28px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(45, 186, 163, 0.3);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(45, 186, 163, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  padding: 10px 20px;
  background: var(--card-bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-danger {
  padding: 10px 20px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

/* Tag Selector & Chips */
.tag-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
}

.selected-filter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
  user-select: none;
}

.tag-chip:hover {
  transform: scale(1.05);
}

.tag-chip.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.tag-chip .remove {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.15);
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  cursor: pointer;
  border: none;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.tag-chip .remove:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.25);
}

.empty-tip {
  color: var(--text-secondary);
  font-size: 13px;
  width: 100%;
  text-align: center;
  padding: 8px 0;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar input,
.filter-bar select,
.filter-bar button {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.filter-bar input {
  flex: 1;
  min-width: 140px;
}

.filter-bar input:focus,
.filter-bar select:focus {
  border-color: var(--primary);
}

/* Dashboard Filter */
.dashboard-filter {
  position: relative;
}

.dashboard-filter select,
.dashboard-filter input[type="number"] {
  min-width: 120px;
  width: auto;
}

.custom-date-range {
  display: flex;
  gap: 8px;
  align-items: center;
}

.custom-date-range input {
  min-width: 130px;
  width: auto;
}

/* Amount Range (side-by-side min/max) */
.amount-range {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 200px;
}

.amount-range input {
  width: 100%;
  min-width: 0;
  flex: 1;
}

.amount-range .amount-sep {
  color: var(--text-secondary);
  font-size: 14px;
  flex-shrink: 0;
}

/* Tag Popup */
.tag-popup {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 160;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  padding: 16px;
  min-width: 280px;
  max-width: 360px;
}

/* Mobile backdrop for tag popup */
.tag-popup-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 155;
}

.tag-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 15px;
}

.tag-popup-header .btn-close {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  max-width: 36px;
  max-height: 36px;
  border: none;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 20px;
  font-weight: 700;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
  line-height: 1;
  box-sizing: border-box;
  flex-shrink: 0;
}

.tag-popup-header .btn-close svg {
  display: block;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.tag-popup-header .btn-close:hover {
  background: var(--bg);
  color: var(--text);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  max-height: 200px;
  overflow-y: auto;
}

/* Tag Groups in filter popup */
.tag-groups {
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.tag-group-section {
  margin-bottom: 12px;
}

.tag-group-section:last-child {
  margin-bottom: 0;
}

.tag-group-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 8px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  transition: opacity 0.2s;
}

.tag-group-section-header:hover {
  opacity: 0.8;
}

.tag-group-section-name {
  flex: 1;
}

.tag-group-select-all {
  font-size: 11px;
  color: var(--primary);
  font-weight: 400;
  white-space: nowrap;
}

.tag-group-section-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-popup-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* Chart Row */
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.chart-half {
  margin-bottom: 0;
}

/* List Card */
.list-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: background 0.3s;
}

.expense-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}

.expense-item:last-child {
  border-bottom: none;
}

.expense-item:hover {
  background: var(--bg);
}

.expense-info {
  flex: 1;
  min-width: 0;
}

.expense-title {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.expense-amount {
  font-size: 18px;
  font-weight: 700;
  color: var(--danger);
  margin-left: 12px;
  white-space: nowrap;
}

.expense-actions {
  display: flex;
  gap: 6px;
  margin-left: 12px;
}

.expense-actions button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s;
}

.expense-actions button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.expense-actions button.delete:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* Tags Card */
.tags-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: background 0.3s;
}

.tag-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}

.tag-item:last-child {
  border-bottom: none;
}

.tag-item:hover {
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.tag-display {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.tag-color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tag-name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.tag-count {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.tag-count:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.tag-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-shrink: 0;
}

.tag-actions button,
.tag-action-icon {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.tag-action-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.tag-actions button:hover,
.tag-action-icon:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tag-actions button.delete:hover,
.tag-action-icon.delete:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* Tag Group Tree */
.tag-group-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  transition: background 0.3s, border-color 0.3s;
}

.tag-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.2s;
  user-select: none;
}

.tag-group-header:hover {
  background: var(--bg);
}

.tag-group-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.tag-group-toggle {
  font-size: 12px;
  color: var(--text-secondary);
  transition: transform 0.25s ease;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.tag-group-toggle.collapsed {
  transform: rotate(-90deg);
}

.tag-group-dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
}

.tag-group-name {
  font-size: 15px;
  font-weight: 600;
}

.tag-group-total {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 8px;
  white-space: nowrap;
}

.tag-group-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.tag-group-header:hover .tag-group-actions {
  opacity: 1;
}

.tag-group-action-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tag-group-action-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tag-group-action-btn.delete:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.tag-group-body {
  max-height: 2000px;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.tag-group-body.collapsed {
  max-height: 0;
}

.tree-tag-item {
  display: flex;
  flex-direction: column;
  padding: 10px 16px 10px 40px;
  border-top: 1px solid var(--border);
  transition: background 0.2s;
  gap: 8px;
}

.tree-tag-item:hover {
  background: var(--bg);
}

.tree-tag-item.empty-group {
  padding: 16px 16px 16px 40px;
  color: var(--text-secondary);
  font-size: 13px;
  font-style: italic;
}

.tree-tag-item .tag-actions button {
  font-size: 11px;
  padding: 4px 8px;
}

/* Move Tag Group List (inside custom modal) */
.move-group-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.move-group-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.move-group-option:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

/* Settings */
.settings-group {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  max-width: 640px;
  transition: background 0.3s;
}

.settings-group h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  gap: 16px;
}

.setting-item:not(:last-child) {
  border-bottom: 1px solid var(--border);
}

.setting-info {
  flex: 1;
  min-width: 0;
}

.setting-title {
  display: block;
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 4px;
}

.setting-desc {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
}

.setting-item.danger .setting-title {
  color: var(--danger);
}

.setting-version {
  padding: 4px 10px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  text-align: center;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.6;
}

.empty-state p {
  font-size: 15px;
  margin-bottom: 20px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 64px;
  z-index: 100;
  transition: background 0.3s, border-color 0.3s;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  position: relative;
}

.nav-item:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.nav-item.active {
  color: var(--primary);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 4px 4px;
}

.nav-icon {
  font-size: 20px;
  line-height: 1;
}

.nav-label {
  font-size: 11px;
  font-weight: 500;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

.mode-toggle-bar {
  display: flex;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px;
  max-width: 560px;
  box-shadow: var(--shadow);
}

.mode-btn {
  flex: 1;
  padding: 12px;
  border: none;
  background: var(--card-bg);
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

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

.mode-btn:not(.active):hover {
  background: var(--primary-light);
  color: var(--primary);
}

.required {
  color: var(--danger);
}

.tag-input-wrap {
  position: relative;
}

.tag-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover);
  max-height: 200px;
  overflow-y: auto;
}

.tag-suggestion-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
}

.tag-suggestion-item:hover,
.tag-suggestion-item.highlighted {
  background: var(--primary-light);
}

.tag-suggestion-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tag-suggestion-group {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.7;
}

.selected-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  min-height: 0;
}

.selected-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  cursor: default;
  border: 2px solid transparent;
  user-select: none;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-tag-chip .remove {
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  max-width: 18px;
  max-height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.15);
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  opacity: 0.7;
  transition: opacity 0.2s;
  flex-shrink: 0;
  box-sizing: border-box;
  padding: 0;
  line-height: 1;
}

.selected-tag-chip .remove svg {
  display: block;
  width: 10px;
  height: 10px;
  flex-shrink: 0;
}

.selected-tag-chip .remove:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.25);
}

/* Trend chart time range selector */
.trend-range-select {
  font-size: 12px;
  font-weight: 400;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--primary);
  cursor: pointer;
  margin-left: 8px;
  outline: none;
  vertical-align: middle;
}

.trend-range-select:focus {
  border-color: var(--primary);
}

/* Rename modal error text */
.rename-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  margin-bottom: 0;
}

.recent-templates {
  max-width: 560px;
  margin-bottom: 16px;
}

.templates-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}

.templates-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.template-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  transition: all 0.2s;
}

.template-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.nl-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 20px;
}

.nl-preview-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.nl-preview-content {
  font-size: 15px;
  line-height: 1.6;
}

.nl-preview-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  align-items: center;
}

.nl-preview-label {
  color: var(--text-secondary);
  min-width: 50px;
  font-size: 13px;
  flex-shrink: 0;
}

.nl-edit-field {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.nl-edit-field:focus {
  border-color: var(--primary);
}

.nl-edit-field.amount {
  color: var(--danger);
  font-weight: 700;
  font-size: 16px;
}

.nl-preview-value {
  font-weight: 500;
  color: var(--text);
}

.nl-preview-value.amount {
  color: var(--danger);
  font-size: 18px;
  font-weight: 700;
}

.nl-tags-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.nl-tag-pill {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
  user-select: none;
}

.nl-tag-pill:hover {
  opacity: 0.7;
}

/* NL textarea */
#nl-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  font-family: inherit;
  outline: none;
  resize: vertical;
  min-height: 100px;
  transition: border-color 0.2s;
}

#nl-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ============================================
   Expense List - Date Grouping
   ============================================ */

.expense-date-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  z-index: 5;
}

.expense-date-label {
  color: var(--text);
}

.expense-date-total {
  color: var(--danger);
  font-weight: 700;
}

.expense-tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 16px;
  margin-bottom: 8px;
}

/* ============================================
   Modals
   ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

.modal-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}

.modal-card.modal-small {
  max-width: 360px;
}

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

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.modal-header .btn-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-header .btn-close:hover {
  background: var(--bg);
  color: var(--text);
}

.modal-body {
  padding: 20px 24px;
}

.modal-body p {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

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

/* ============================================
   Tag Color Input in List
   ============================================ */

.tag-color-input {
  width: 32px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  cursor: pointer;
  transition: border-color 0.2s;
}

.tag-color-input:hover {
  border-color: var(--primary);
}

/* Toast Notification */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--success);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 200;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ============================================
   Toggle Switch
   ============================================ */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--border);
  border-radius: 26px;
  transition: background 0.3s;
}

.toggle-slider::before {
  position: absolute;
  content: '';
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* ============================================
   Import Preview
   ============================================ */
.import-actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  justify-content: flex-end;
}

.import-preview-section {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 12px;
}

.import-mapping-info {
  margin-bottom: 12px;
}

.import-mapping-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.import-mapping-tag {
  display: inline-block;
  padding: 3px 10px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.import-missing {
  color: var(--danger);
  font-size: 12px;
}

.import-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.import-stat {
  font-size: 13px;
  font-weight: 500;
}

.import-stat.valid {
  color: var(--success);
}

.import-stat.invalid {
  color: var(--warning);
}

.import-stat.total {
  color: var(--text-secondary);
}

.import-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.import-preview-table th,
.import-preview-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.import-preview-table th {
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--card-bg);
}

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

.import-preview-more {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}

/* Scrollable import table */
.import-table-wrap {
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}

.import-table-wrap .import-preview-table {
  border: none;
}

.import-table-wrap .import-preview-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.import-table-wrap .import-preview-table thead th {
  background: var(--card-bg);
  border-bottom: 2px solid var(--border);
}

.import-table-wrap .import-preview-table tbody tr:last-child td {
  border-bottom: none;
}

/* Valid / invalid row indicators */
.import-row-valid td {
  border-left: 3px solid var(--success);
}

.import-row-invalid td {
  border-left: 3px solid var(--danger);
  background: rgba(231, 76, 60, 0.04);
}

[data-theme="dark"] .import-row-invalid td {
  background: rgba(231, 76, 60, 0.10);
}

.import-row-num {
  font-weight: 600;
  color: var(--text-secondary);
  width: 32px;
  text-align: center;
}

.import-row-status {
  text-align: center;
  width: 36px;
}

.import-cell-valid {
  color: var(--text);
  font-weight: 500;
}

/* Inline edit inputs */
.import-edit-input {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.import-edit-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.import-edit-input::placeholder {
  color: var(--text-secondary);
  font-size: 11px;
}

/* Invalid field input — red border */
.import-edit-invalid {
  border-color: var(--danger);
  background: rgba(231, 76, 60, 0.04);
}

.import-edit-invalid:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

/* Column widths */
.import-preview-table .col-num { width: 36px; }
.import-preview-table .col-date { width: 120px; }
.import-preview-table .col-amount { width: 90px; }
.import-preview-table .col-item { width: auto; }
.import-preview-table .col-tags { width: auto; }
.import-preview-table .col-status { width: 40px; }
.import-preview-table .col-del { width: 40px; }

/* Delete button per row */
.import-row-del {
  text-align: center;
  padding: 2px !important;
}

.import-del-btn {
  width: 26px;
  height: 26px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
  padding: 0;
}

.import-del-btn:hover {
  background: rgba(231, 76, 60, 0.12);
  color: var(--danger);
  border-color: var(--danger);
}

/* Delete invalid rows button */
.import-del-invalid-btn {
  border-color: var(--danger);
  color: var(--danger);
}

.import-del-invalid-btn:hover {
  background: rgba(231, 76, 60, 0.08);
}

/* Re-validate button row */
.import-preview-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding-top: 8px;
}

/* ============================================
   Guide Overlay
   ============================================ */
.guide-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}

.guide-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.guide-card {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 28px 32px;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow-hover);
  animation: guideSlideIn 0.35s ease;
}

@keyframes guideSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.guide-fade-out {
  animation: guideFadeOut 0.3s ease forwards;
}

@keyframes guideFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

.guide-step-indicator {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 16px;
}

.guide-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s;
}

.guide-dot.active {
  background: var(--primary);
}

.guide-title {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 12px;
  color: var(--text);
}

.guide-content {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 24px;
}

.guide-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.guide-skip {
  display: block;
  margin: 16px auto 0;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.2s;
}

.guide-skip:hover {
  color: var(--text);
}

/* Responsive Design */
@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  header {
    padding: 10px 16px;
  }

  .logo {
    font-size: 16px;
  }

  .logo svg {
    width: 24px;
    height: 24px;
  }

  .back-btn {
    padding: 5px 10px;
    font-size: 12px;
  }

  .theme-toggle {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  main {
    padding: 16px;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-value {
    font-size: 18px;
  }

  .chart-wrapper {
    height: 220px;
  }

  .form-card {
    padding: 16px;
  }

  .form-group.inline {
    flex-wrap: wrap;
  }

  .form-group.inline input[type="text"] {
    width: 100%;
  }

  .filter-bar {
    flex-direction: column;
  }

  .filter-bar input,
  .filter-bar select,
  .filter-bar button {
    width: 100%;
  }

  .dashboard-filter select,
  .dashboard-filter input[type="number"] {
    width: 100%;
    min-width: 0;
  }

  .amount-range {
    width: 100%;
  }

  .amount-range input {
    min-width: 0;
  }

  .custom-date-range {
    width: 100%;
  }

  .custom-date-range input {
    width: 100%;
  }

  .chart-row {
    grid-template-columns: 1fr;
  }

  .tag-popup {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 60vh;
    z-index: 160;
    animation: slideUp 0.3s ease;
    padding: 20px 16px 16px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
  }

  .tag-popup-backdrop {
    display: block;
  }

  .tag-popup-header {
    font-size: 16px;
    padding-bottom: 12px;
  }

  .tag-popup-header .btn-close {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    max-width: 40px;
    max-height: 40px;
    font-size: 22px;
  }

  .expense-item {
    flex-wrap: wrap;
    gap: 8px;
  }

  input[type="date"] {
    max-width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
  }

  .expense-amount {
    margin-left: auto;
  }

  .expense-actions {
    width: 100%;
    justify-content: flex-end;
    margin-left: 0;
  }

  .tag-item {
    flex-wrap: wrap;
    gap: 8px;
  }

  .tree-tag-item {
    padding: 10px 14px 10px 28px;
    gap: 6px;
  }

  .tree-tag-item .tag-actions {
    justify-content: flex-end;
    gap: 4px;
  }

  .tag-actions {
    justify-content: flex-end;
    gap: 4px;
  }

  .tag-action-icon {
    width: 28px;
    height: 28px;
  }

  .tag-name {
    max-width: 140px;
  }

  .modal-card {
    max-width: 100%;
  }

  .modal-header {
    padding: 16px 20px;
  }

  .modal-body {
    padding: 16px 20px;
  }

  .modal-footer {
    padding: 12px 20px;
  }

  .expense-date-header {
    padding: 10px 16px;
    font-size: 13px;
  }

  .setting-item {
    flex-wrap: wrap;
  }

  .settings-group {
    padding: 16px;
  }

  .bottom-nav {
    height: 56px;
  }

  .nav-icon {
    font-size: 18px;
  }

  .nav-label {
    font-size: 10px;
  }

  body {
    padding-bottom: 64px;
  }
}

@media (max-width: 480px) {
  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
  }

  .stat-label {
    font-size: 11px;
  }

  .stat-value {
    font-size: 16px;
  }

  .import-table-wrap {
    max-height: 360px;
    overflow-x: auto;
  }

  .import-preview-table {
    min-width: 600px;
  }

  .import-edit-input {
    font-size: 12px;
    padding: 3px 6px;
  }

  .import-preview-actions {
    flex-wrap: wrap;
    gap: 8px;
  }

  .import-preview-actions .btn-secondary {
    font-size: 13px;
    padding: 8px 14px;
  }
}
