/* ── Root Variables ─────────────────────────────────────────────────────── */
:root {
  --bg: #080d18;
  --bg-nav: rgba(8, 13, 24, 0.92);
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);
  --bg-input: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.18);
  --text: #f1f5f9;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.2s ease;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 80% 40% at 50% -20%, rgba(99, 102, 241, 0.15) 0%, transparent 60%),
    radial-gradient(ellipse 50% 30% at 80% 80%, rgba(16, 185, 129, 0.08) 0%, transparent 50%);
}

/* ── Nav ────────────────────────────────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 64px;
  background: var(--bg-nav);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.nav-logo {
  font-size: 1.4rem;
}

.nav-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sync-status {
  color: var(--text-3);
  font-size: 0.8rem;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.87rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-2);
  box-shadow: 0 0 30px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.btn-lg {
  padding: 0.8rem 2rem;
  font-size: 0.95rem;
}

.btn-full {
  width: 100%;
  justify-content: center;
  margin-top: 0.75rem;
}

.btn-icon {
  font-size: 1rem;
}

.btn:active {
  transform: scale(0.97);
}

/* ── Main ───────────────────────────────────────────────────────────────── */
.main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ── Section Headers ────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.section-sub {
  font-size: 0.8rem;
  color: var(--text-3);
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), background var(--transition);
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 0;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
}

.card-sub {
  font-size: 0.8rem;
  color: var(--text-3);
}

/* ── Balance Grid ───────────────────────────────────────────────────────── */
.balance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.balance-card {
  padding: 1.5rem;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  cursor: default;
  transition: all var(--transition);
}

.balance-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--success));
  opacity: 0;
  transition: opacity var(--transition);
}

.balance-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}

.balance-card:hover::before {
  opacity: 1;
}

.balance-institution {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.5rem;
}

.balance-amount {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.balance-currency {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-2);
  margin-left: 0.2rem;
}

.balance-iban {
  font-size: 0.75rem;
  color: var(--text-3);
  font-family: monospace;
}

.balance-expiry {
  font-size: 0.72rem;
  color: var(--warning);
  margin-top: 0.5rem;
}

/* ── Charts ─────────────────────────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.chart-card {
  padding-bottom: 1.5rem;
}

.chart-wrapper {
  padding: 1.25rem 1.5rem;
  height: 260px;
}

/* Taller wrapper for horizontal category bar chart */
.chart-wrapper-tall {
  padding: 0.5rem 1rem 1rem;
  height: 480px;
}


.chart-wrapper canvas {
  max-height: 100% !important;
}

/* Category legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0 1.5rem 1rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-2);
}

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

/* ── Transaction Table ──────────────────────────────────────────────────── */
.table-card {
  overflow: hidden;
}

.table-card .card-header {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.table-filters {
  display: flex;
  gap: 0.6rem;
}

.filter-input,
.filter-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.83rem;
  padding: 0.4rem 0.75rem;
  outline: none;
  transition: border-color var(--transition);
}

.filter-input {
  min-width: 180px;
}

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

.filter-select option {
  background: #1e2536;
}

.table-wrap {
  overflow-x: auto;
}

.txn-table {
  width: 100%;
  border-collapse: collapse;
}

.txn-table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.txn-table td {
  padding: 0.75rem 1.5rem;
  font-size: 0.865rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

.txn-table tr:last-child td {
  border-bottom: none;
}

.txn-table tbody tr {
  transition: background var(--transition);
}

.txn-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.txn-date {
  color: var(--text-2);
  white-space: nowrap;
}

.txn-merchant {
  font-weight: 500;
}

.txn-desc {
  color: var(--text-3);
  font-size: 0.8rem;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.amount-col {
  text-align: right;
}

.txn-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.txn-amount.debit {
  color: var(--danger);
}

.txn-amount.credit {
  color: var(--success);
}

/* Category badge */
.cat-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 500;
  white-space: nowrap;
}

.table-empty {
  text-align: center;
  padding: 3rem;
  color: var(--text-3);
  font-size: 0.9rem;
}

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: #111827;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-weight: 600;
  font-size: 1rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
  transition: all var(--transition);
}

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

.modal-search {
  padding: 1rem 1.5rem 0.5rem;
}

.modal-search .filter-input {
  width: 100%;
}

.institution-list {
  overflow-y: auto;
  padding: 0.5rem 1rem 1rem;
  flex: 1;
}

.inst-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

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

.inst-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  overflow: hidden;
}

.inst-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.inst-name {
  font-size: 0.9rem;
  font-weight: 500;
}

.inst-id {
  font-size: 0.75rem;
  color: var(--text-3);
}

.finalize-box {
  padding: 2rem 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.finalize-icon {
  font-size: 2.5rem;
}

.finalize-box h4 {
  font-size: 1.05rem;
  font-weight: 600;
}

.finalize-box p {
  color: var(--text-2);
  font-size: 0.88rem;
}

.finalize-box .filter-input {
  width: 100%;
  margin-top: 0.25rem;
}

/* ── Empty State ────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  gap: 1rem;
}

.empty-icon {
  font-size: 4rem;
}

.empty-state h2 {
  font-size: 1.4rem;
  font-weight: 700;
}

.empty-state p {
  color: var(--text-2);
  font-size: 0.95rem;
}

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1e2942;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 999;
  animation: slideUp 0.25s ease;
  white-space: nowrap;
}

.toast.success {
  border-color: var(--success);
  color: var(--success);
}

.toast.error {
  border-color: var(--danger);
  color: var(--danger);
}

/* ── Loading ────────────────────────────────────────────────────────────── */
.loading {
  color: var(--text-3);
  font-size: 0.88rem;
  padding: 1rem;
  text-align: center;
}

.skeleton {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 25%, rgba(255, 255, 255, 0.09) 50%, rgba(255, 255, 255, 0.04) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
  height: 1em;
}

/* ── Animations ─────────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* ── Utils ──────────────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ── Spending total label ───────────────────────────────────────────────── */
.spending-total {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  padding: 0.25rem 1.5rem 0.75rem;
  letter-spacing: -0.02em;
}

/* ── Legend with amounts ────────────────────────────────────────────────── */
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.legend-item span[style*="margin-left:auto"] {
  margin-left: auto !important;
}


/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .charts-row {
    grid-template-columns: 1fr;
  }

  .nav {
    padding: 0 1rem;
  }

  .nav-title {
    display: none;
  }

  .sync-status {
    display: none;
  }

  .main {
    padding: 1.25rem 1rem 3rem;
  }

  .table-filters {
    flex-direction: column;
  }
}