/* Finalyse - Budget-Tool */
:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --positive: #22c55e;
  --negative: #ef4444;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.75rem 2rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.5px;
}
.nav-links { display: flex; gap: 0.25rem; }
.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  transition: all 0.15s;
}
.nav-links a:hover { color: var(--text); background: var(--bg-input); }
.nav-links a.active { color: var(--text); background: var(--accent); }

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 600; }

/* Month nav */
.month-nav { display: flex; align-items: center; gap: 0.75rem; }
.month-label { font-weight: 600; min-width: 140px; text-align: center; }

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem;
  border: 1px solid var(--border);
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.card-grid.two { grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); }
.card-grid.three { grid-template-columns: repeat(3, 1fr); }

.summary-card { text-align: center; }
.card-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.25rem; }
.card-sublabel { font-size: 0.75rem; color: var(--text-muted); }
.card-value { font-size: 1.75rem; font-weight: 700; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }

/* Sections */
.section { margin-bottom: 2rem; }
.section h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-header h2 { margin-bottom: 0; }

/* Category bars (dashboard) */
.category-bars { display: flex; flex-direction: column; gap: 0.75rem; }
.category-bar-row {
  display: grid;
  grid-template-columns: 160px 1fr 140px;
  align-items: center;
  gap: 0.75rem;
}
.cat-info { display: flex; align-items: center; gap: 0.5rem; }
.cat-icon { font-size: 1.1rem; }
.cat-name { font-size: 0.875rem; }
.cat-bar-wrap {
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}
.cat-bar { height: 100%; border-radius: 4px; transition: width 0.3s; }
.cat-amounts { display: flex; gap: 0.25rem; font-size: 0.8rem; justify-content: flex-end; }
.cat-spent { font-weight: 600; }
.cat-budget { color: var(--text-muted); }

/* Trend chart */
.trend-chart {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem;
  border: 1px solid var(--border);
}
.chart-bars { display: flex; align-items: flex-end; justify-content: space-around; gap: 1rem; height: 180px; padding-bottom: 1.5rem; }
.chart-month { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; }
.chart-bar-group { display: flex; gap: 4px; align-items: flex-end; }
.chart-bar { width: 24px; border-radius: 4px 4px 0 0; min-height: 2px; transition: height 0.3s; }
.income-bar { background: var(--positive); opacity: 0.8; }
.expense-bar { background: var(--negative); opacity: 0.8; }
.chart-label { font-size: 0.75rem; color: var(--text-muted); }
.chart-legend { display: flex; gap: 1rem; justify-content: center; margin-top: 0.5rem; }
.legend-item { display: flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; color: var(--text-muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.income-dot { background: var(--positive); }
.expense-dot { background: var(--negative); }

/* Transaction list */
.tx-list { display: flex; flex-direction: column; }
.tx-row {
  display: grid;
  grid-template-columns: 50px 36px 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}
.tx-date { font-size: 0.8rem; color: var(--text-muted); }
.tx-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
}
.tx-peer { font-size: 0.875rem; font-weight: 500; }
.tx-reason { font-size: 0.75rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 400px; }
.tx-amount { font-weight: 600; font-size: 0.9rem; text-align: right; white-space: nowrap; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th { text-align: left; padding: 0.6rem 0.75rem; color: var(--text-muted); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
.table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
.table tr:hover td { background: rgba(99, 102, 241, 0.05); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.tx-reason-cell { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-inline { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; }
.form-card { margin-top: 1rem; }
.form-card h3 { font-size: 0.95rem; margin-bottom: 0.75rem; }
.form-actions { margin-top: 1.5rem; }
.input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  width: 100%;
}
.input:focus { outline: none; border-color: var(--accent); }
.input-sm { max-width: 120px; }
.input-xs { max-width: 60px; }
.input-color { width: 40px; height: 36px; padding: 2px; cursor: pointer; }
select.input { cursor: pointer; }
.cat-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: none;
  font-size: 0.875rem;
  cursor: pointer;
  background: var(--bg-input);
  color: var(--text);
  text-decoration: none;
  transition: all 0.15s;
}
.btn:hover { background: #475569; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-lg { padding: 0.65rem 1.5rem; font-size: 1rem; }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-secondary { background: transparent; border: 1px solid var(--border); }
.btn-danger { background: #7f1d1d; color: #fca5a5; }
.btn-danger:hover { background: #991b1b; }

/* Badges */
.badge { font-size: 0.75rem; background: var(--bg-input); padding: 0.15rem 0.5rem; border-radius: 99px; font-weight: 500; }
.badge-sm { font-size: 0.7rem; }

/* Filter bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.filter-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; flex: 1; }
.filter-form .input { width: auto; min-width: 140px; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1.5rem; font-size: 0.875rem; color: var(--text-muted); }

/* Budget page */
.budget-list { display: flex; flex-direction: column; gap: 1rem; }
.budget-row { background: var(--bg-card); border-radius: var(--radius); padding: 1rem; border: 1px solid var(--border); }
.budget-row.over-budget { border-color: var(--negative); }
.budget-header { display: flex; align-items: center; gap: 1rem; }
.cat-icon-lg { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.budget-info { flex: 1; }
.budget-name { font-weight: 600; font-size: 0.95rem; }
.budget-stats { font-size: 0.8rem; color: var(--text-muted); }
.budget-input-wrap { width: 120px; }
.budget-bar-wrap { height: 6px; background: var(--bg-input); border-radius: 3px; margin-top: 0.75rem; overflow: hidden; }
.budget-bar { height: 100%; border-radius: 3px; transition: width 0.3s; }
.budget-pct { font-size: 0.75rem; color: var(--text-muted); text-align: right; margin-top: 0.25rem; }

/* Category page */
.category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.category-card { background: var(--bg-card); border-radius: var(--radius); padding: 0.75rem 1rem; border: 1px solid var(--border); }
.cat-card-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.35rem; }
.cat-card-stats { font-size: 0.75rem; color: var(--text-muted); display: flex; gap: 0.75rem; margin-bottom: 0.5rem; }

/* Sync page */
.sync-status { margin-top: 1.5rem; padding: 1rem; background: var(--bg); border-radius: var(--radius); border: 1px solid var(--border); }
.sync-spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sync-log { margin-top: 0.75rem; max-height: 200px; overflow-y: auto; font-size: 0.8rem; font-family: monospace; }
.log-entry { padding: 0.15rem 0; color: var(--text-muted); }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-top: 1rem; font-size: 0.875rem; }
.alert-success { background: rgba(34, 197, 94, 0.1); border: 1px solid rgba(34, 197, 94, 0.3); color: var(--positive); }

/* Empty state */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state .btn { margin-top: 1rem; }

.hint { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1rem; }
.inline { display: inline; }

/* Footer */
.app-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  margin-top: 2rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  opacity: 0.6;
}

/* Summary card enhancements */
.card-icon-wrap {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  margin: 0 auto 0.5rem;
}
.positive-bg { background: rgba(34, 197, 94, 0.15); }
.negative-bg { background: rgba(239, 68, 68, 0.15); }
.accent-bg { background: rgba(99, 102, 241, 0.15); }

.savings-rate {
  font-size: 0.8rem;
  margin-top: 0.35rem;
  font-weight: 500;
}

/* Card title */
.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

/* Chart containers */
.chart-container {
  position: relative;
  height: 280px;
}
.donut-container {
  height: 300px;
}

/* Alert warning */
.alert-warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #f59e0b;
  margin-bottom: 1.5rem;
}
.alert-warning a {
  color: var(--accent);
  text-decoration: underline;
}

/* Top peers */
.top-peers-list { display: flex; flex-direction: column; gap: 0.5rem; }
.top-peer-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.top-peer-row:last-child { border-bottom: none; }
.peer-rank { font-size: 0.8rem; color: var(--text-muted); width: 22px; }
.peer-name { flex: 1; font-size: 0.875rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-amount { font-weight: 600; font-size: 0.875rem; white-space: nowrap; }
.peer-count { flex-shrink: 0; }

/* Accounts list */
.accounts-list { display: flex; flex-direction: column; gap: 0.5rem; }
.account-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.account-row:last-child { border-bottom: none; }
.account-icon { font-size: 1.2rem; }
.account-name { font-size: 0.875rem; font-weight: 500; }
.account-iban { font-size: 0.75rem; color: var(--text-muted); }

/* Transaction tooltip */
.tx-row-clickable { position: relative; cursor: default; }
.tx-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50px;
  right: 50px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text);
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  white-space: normal;
  word-break: break-word;
}

/* Rule create button (transactions) */
.cat-cell-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.btn-rule-create {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-rule-create:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Rule inline form (transactions) */
.rule-form-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.rule-form-peer {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  padding: 0.2rem 0.5rem;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 4px;
}
.rule-form-category {
  min-width: 160px;
  font-size: 0.8rem;
}

/* Rule edit (categories page) */
.rule-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  flex-wrap: wrap;
}
.rule-cat-edit, .rule-pattern-edit {
  font-size: 0.8rem;
  padding: 0.3rem 0.5rem;
  width: auto;
  min-width: 120px;
}

/* Monthly overview */
.monthly-categories { display: flex; flex-direction: column; gap: 0.5rem; }
.monthly-cat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.monthly-cat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
}
.monthly-cat-header:hover { background: rgba(99, 102, 241, 0.05); }
.monthly-cat-header .cat-info { display: flex; align-items: center; gap: 0.5rem; flex: 1; }
.monthly-cat-header .cat-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.monthly-cat-amount { font-weight: 700; font-size: 1rem; white-space: nowrap; }
.monthly-chevron {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.monthly-chevron.open { transform: rotate(90deg); }
.monthly-cat-transactions {
  border-top: 1px solid var(--border);
  padding: 0.5rem;
  background: var(--bg);
}
.monthly-tx-table { font-size: 0.8rem; }
.monthly-tx-table th { font-size: 0.7rem; }
.monthly-tx-loading, .monthly-tx-empty {
  text-align: center;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 768px) {
  .navbar { flex-direction: column; gap: 0.5rem; padding: 0.75rem 1rem; }
  .nav-links { overflow-x: auto; width: 100%; }
  .card-grid.three { grid-template-columns: 1fr; }
  .category-bar-row { grid-template-columns: 120px 1fr 100px; }
  .tx-row { grid-template-columns: 40px 30px 1fr auto; }
  .tx-reason { max-width: 150px; }
  .filter-form .input { min-width: 100px; }
  .form-row { grid-template-columns: 1fr; }
  .budget-header { flex-wrap: wrap; }
}
