/* ============================================================
   Components – Shared UI: Grids, Cards, Stats, Lists, Charts
   ============================================================ */

/* ─── Grid Layouts ────────────────────────────────────────── */
.grid {
  display: grid;
  gap: 16px;
}

.grid-2col {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.grid-3col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.grid-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 768px) {
  .grid-2col,
  .grid-3col,
  .grid-split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 400px) {
  .grid {
    gap: 12px;
  }
}

/* ─── Card ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-padding {
  padding: 20px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-action {
  font-size: 12px;
  color: var(--brand);
  cursor: pointer;
  font-weight: 500;
}

.card-action:hover {
  text-decoration: underline;
}

/* ─── Currency Tabs ───────────────────────────────────────── */
.currency-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.currency-tab {
  flex: 1;
  padding: 8px 12px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.currency-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ─── Account Scroll (Horizontal Cards) ───────────────────── */
.account-scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
}

.account-card {
  min-width: 220px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
  scroll-snap-align: start;
  cursor: pointer;
  transition: border-color 0.25s ease;
}

.account-card:hover {
  border-color: var(--brand);
}

.account-card .account-name {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.account-card .account-balance {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.account-card .account-currency {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

.account-card.active {
  border-color: var(--brand);
  background: var(--brand-glow);
}

/* ─── Stats Grid ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

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

.stat-value.income {
  color: var(--brand);
}

.stat-value.expense {
  color: var(--expense);
}

/* ─── Sparkline ───────────────────────────────────────────── */
.sparkline {
  width: 100%;
  height: 40px;
  margin-top: 8px;
}

/* ─── Chart Wrapper ───────────────────────────────────────── */
.chart-wrapper {
  position: relative;
  width: 100%;
  padding: 16px 0;
}

.chart-wrapper canvas {
  width: 100% !important;
  height: 200px !important;
}

.donut-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

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

.donut-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── Legend ───────────────────────────────────────────────── */
.legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-name {
  flex: 1;
  color: var(--text-muted);
}

.legend-percent {
  font-weight: 600;
  color: var(--text);
  min-width: 36px;
  text-align: end;
}

.legend-value {
  color: var(--text-dim);
  font-size: 11px;
  min-width: 60px;
  text-align: end;
}

/* ─── List Items ──────────────────────────────────────────── */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

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

.list-item:hover {
  background: var(--surface-hover);
}

.list-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background: var(--surface-2);
  color: var(--text-muted);
}

.list-body {
  flex: 1;
  min-width: 0;
}

.list-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-subtitle {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.list-right {
  text-align: end;
  flex-shrink: 0;
}

.list-amount {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.list-amount.income {
  color: var(--brand);
}

.list-amount.expense {
  color: var(--expense);
}

.list-date {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ─── List Actions (Swipe/Hover) ──────────────────────────── */
.list-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.list-item:hover .list-actions {
  opacity: 1;
}

.action-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  background: var(--surface-2);
  transition: color 0.2s ease, background-color 0.2s ease;
}

.action-btn:hover {
  color: var(--brand);
  background: var(--brand-glow);
}

.action-btn.danger:hover {
  color: var(--expense);
  background: var(--expense-glow);
}

/* ─── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge-income {
  background: var(--brand-glow);
  color: var(--brand);
}

.badge-expense {
  background: var(--expense-glow);
  color: var(--expense);
}

.badge-draft {
  background: var(--surface-2);
  color: var(--text-dim);
}

.badge-pending {
  background: var(--gold-glow);
  color: var(--gold);
}

.badge-sent {
  background: var(--info-glow);
  color: var(--info);
}

/* ─── Filter Row ──────────────────────────────────────────── */
.filter-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filter-btn {
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 20px;
  cursor: pointer;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.filter-btn:hover {
  border-color: var(--brand);
  color: var(--text);
}

.filter-btn.active {
  background: var(--brand-glow);
  border-color: var(--brand);
  color: var(--brand);
}

/* ─── Invoice Stats ───────────────────────────────────────── */
.invoice-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.invoice-stat-card {
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}

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

.invoice-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─── Empty State ─────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-text {
  font-size: 13px;
  color: var(--text-dim);
}

/* ─── Settings ────────────────────────────────────────────── */
.settings-group {
  margin-bottom: 24px;
}

.settings-group-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  padding: 0 16px;
  margin-bottom: 8px;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.settings-item:hover {
  background: var(--surface-hover);
}

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

.settings-item-body {
  flex: 1;
  min-width: 0;
}

.settings-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.settings-item-subtitle {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.settings-item-value {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ─── Add Row ─────────────────────────────────────────────── */
.add-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.25s ease, color 0.25s ease;
}

.add-row:hover {
  border-color: var(--brand);
  color: var(--brand);
}

/* ─── Chart Tooltip ───────────────────────────────────────── */
.chart-tooltip {
  position: absolute;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

/* ─── Issues / Tasks Page ─────────────────────────────────── */
.issues-filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

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

.issues-filter-row + .issues-filter-row {
  margin-top: 8px;
}

.issue-filter-select,
.issue-filter-date,
.issue-filter-text {
  padding: 7px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease;
}

.issue-filter-select:focus,
.issue-filter-date:focus,
.issue-filter-text:focus {
  border-color: var(--brand);
}

.issue-filter-select {
  min-width: 120px;
}

.issue-filter-text {
  flex: 1;
  min-width: 140px;
}

.issue-filter-btn {
  padding: 7px 16px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: #fff;
  background: var(--brand);
  border: none;
  transition: opacity 0.2s ease;
}

.issue-filter-btn:hover {
  opacity: 0.85;
}

.issue-filter-btn.secondary {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.issues-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.issue-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

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

.issue-item:hover {
  background: var(--surface-hover);
}

.issue-id {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 36px;
}

.issue-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.tracker-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-muted);
  margin-inline-end: 6px;
}

.priority-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}

.priority-high {
  background: var(--expense-glow);
  color: var(--expense);
}

.priority-low {
  background: var(--surface-2);
  color: var(--text-dim);
}

.done-bar {
  position: relative;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}

.done-fill {
  height: 100%;
  background: var(--brand);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.done-text {
  position: absolute;
  right: 0;
  top: -14px;
  font-size: 10px;
  color: var(--text-dim);
}

/* ─── Pagination Bar ─────────────────────────────────────────── */
.pg-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.pg-info {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.pg-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.pg-btn {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  user-select: none;
}

.pg-btn:hover:not(:disabled):not(.active) {
  border-color: var(--brand);
  color: var(--text);
  background: var(--brand-glow);
}

.pg-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 700;
  cursor: default;
}

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

.pg-btn.pg-edge {
  font-size: 11px;
  padding: 0 10px;
}

.pg-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  font-size: 12px;
  color: var(--text-dim);
  user-select: none;
}

@media (max-width: 480px) {
  .pg-bar {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    margin-bottom: 0;
  }
  .pg-nav {
    justify-content: center;
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  .pg-bar {
    /* The .content-area's padding-bottom (= --mobile-nav-h + safe-bottom)
       reserves enough room below this element to clear the floating dock
       and the FAB, so the bar's own margin can stay minimal here. */
    margin-bottom: 0;
  }
}

/* ─── Autocomplete Dropdown ─────────────────────────────── */
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  z-index: 300;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.1s;
}
.autocomplete-item:hover,
.autocomplete-item.active {
  background: var(--brand-glow);
}
.autocomplete-item .aci-icon {
  font-size: 16px;
  flex-shrink: 0;
}
.autocomplete-item .aci-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.autocomplete-item .aci-type {
  font-size: 9px;
  color: var(--text-faint);
  text-transform: uppercase;
  flex-shrink: 0;
}

/* ─── Contact Combobox ───────────────────────────────────── */
.contact-combobox {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.contact-combobox-input-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
}
.contact-combobox-input-wrap .form-input {
  width: 100%;
  padding-right: 32px;
}
.combobox-arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  transition: transform 0.2s ease;
}
.contact-combobox-input-wrap:focus-within .combobox-arrow {
  transform: translateY(-50%) rotate(180deg);
}
.contact-add-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  font-size: 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* ─── Radio Group ───────────────────────────────────────── */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.radio-group .radio-btn {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s ease;
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.radio-group .radio-btn input[type="radio"] {
  display: none;
}
.radio-group .radio-btn.active {
  border-color: var(--brand);
  background: var(--brand-glow);
  color: var(--brand);
}

/* ─── Tag Group ─────────────────────────────────────────── */
.tag-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-group .tag-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tag-group .tag-btn.active {
  border-color: var(--brand);
  background: var(--brand-glow);
  color: var(--brand);
}
