/* Foley Finance Dashboard — Dark Theme */

:root {
  --bg-primary: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #1f2233;
  --bg-input: #252836;
  --border: #2a2d37;
  --border-hover: #3a3d47;
  --text-primary: #e4e4e7;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-dim: rgba(99, 102, 241, 0.15);
  --success: #22c55e;
  --success-dim: rgba(34, 197, 94, 0.15);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.15);
  --warning: #eab308;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Scrollbar ──────────────────────────── */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* ── Header ─────────────────────────────── */

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-title .logo {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  color: white;
}

.sync-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
}

.sync-dot.error {
  background: var(--danger);
}

/* ── Filter Bar ─────────────────────────── */

.filter-bar {
  position: sticky;
  top: 57px;
  z-index: 99;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-bar label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-bar input[type="date"],
.filter-bar select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 0.85rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}

.filter-bar input[type="date"]:focus,
.filter-bar select:focus {
  border-color: var(--accent);
}

.filter-bar input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
}

.filter-sep {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.btn {
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.78rem;
}

.filter-active-badge {
  background: var(--accent-dim);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  display: none;
  align-items: center;
  gap: 6px;
}

.filter-active-badge.visible {
  display: inline-flex;
}

.filter-active-badge .clear-x {
  cursor: pointer;
  font-weight: 700;
  opacity: 0.7;
}

.filter-active-badge .clear-x:hover {
  opacity: 1;
}

/* ── Dashboard Grid ─────────────────────── */

.dashboard {
  padding: 16px;
  max-width: 1600px;
  margin: 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.grid .full-width {
  grid-column: 1 / -1;
}

.grid .charts-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 2fr;
  grid-template-rows: auto;
  gap: 12px;
}

.grid .charts-row .chart-spending-wrap {
  grid-row: 1 / 2;
}

.grid .charts-row .chart-spending-wrap .chart-container {
  height: 300px;
}

.grid .charts-row .charts-right {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.grid .charts-row .charts-right .chart-container {
  height: 200px;
}

/* ── Card ───────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s;
  position: relative;
  overflow: hidden;
}

.card:hover {
  border-color: var(--border-hover);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.card-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Chart Containers ───────────────────── */

.chart-container {
  position: relative;
  height: 200px;
  width: 100%;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ── Tables ──────────────────────────────── */

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

thead th {
  background: var(--bg-input);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  white-space: nowrap;
}

tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

tbody tr:hover {
  background: rgba(99, 102, 241, 0.04);
}

.summary-row td {
  font-weight: 700;
  border-top: 2px solid var(--border-hover);
  padding-top: 12px;
}

/* ── Amount formatting ──────────────────── */

.amount-positive {
  color: var(--success);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.amount-negative {
  color: var(--danger);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.amount-neutral {
  color: var(--text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ── Category pills ─────────────────────── */

.category-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ── Amazon order matching ──────────────── */

.matched-row {
  background: var(--success-dim) !important;
}

.unmatched-row {
  opacity: 0.6;
}

.items-cell {
  max-width: 250px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.items-text {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  max-width: 250px;
}

.items-text.expanded {
  white-space: normal;
  overflow: visible;
}

/* ── Transaction Filters ───────────────── */

.txn-filters {
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.txn-filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.txn-account-buttons {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.txn-filter-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.txn-filter-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--bg-input);
}

.txn-filter-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

.txn-filter-btn .btn-count {
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 3px;
  font-size: 0.65rem;
}

.txn-filter-btn.active .btn-count {
  color: var(--accent-hover);
}

.txn-account-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  padding: 4px 8px;
  font-size: 0.72rem;
  font-family: var(--font);
  outline: none;
  cursor: pointer;
}

.txn-account-select:focus {
  border-color: var(--accent);
}

/* ── Loading & Error States ─────────────── */

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 17, 23, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  z-index: 10;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-input) 25%, var(--border) 50%, var(--bg-input) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.error-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.error-state p {
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.error-banner {
  background: var(--danger-dim);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  margin: 24px;
  color: var(--danger);
  font-weight: 500;
  display: none;
  align-items: center;
  gap: 8px;
}

.error-banner.visible {
  display: flex;
}

/* ── No Data ────────────────────────────── */

.no-data {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Load More ──────────────────────────── */

.load-more-wrapper {
  text-align: center;
  padding: 16px 0 4px;
}

/* ── Pending badge ──────────────────────── */

.pending-badge {
  display: inline-block;
  background: var(--warning);
  color: #000;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: 6px;
}

/* ── Responsive ─────────────────────────── */

@media (max-width: 1100px) {
  .grid .charts-row {
    grid-template-columns: 1fr;
  }

  .grid .charts-row .charts-right {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .grid .charts-row {
    grid-template-columns: 1fr;
  }

  .grid .charts-row .charts-right {
    grid-template-columns: 1fr;
  }

  .header {
    padding: 12px 16px;
  }

  .filter-bar {
    padding: 10px 16px;
    top: 49px;
  }

  .dashboard {
    padding: 12px;
  }

  .card {
    padding: 12px;
  }
}

@media (max-width: 600px) {
  .header-title {
    font-size: 1.1rem;
  }

  .filter-bar {
    gap: 8px;
  }

  .filter-bar label {
    display: none;
  }

  .filter-bar input[type="date"],
  .filter-bar select {
    font-size: 0.8rem;
    padding: 6px 8px;
  }

  tbody td, thead th {
    padding: 4px 8px;
    font-size: 0.75rem;
  }
}
