:root {
  --bg: #1a1b26;
  --surface: #24283b;
  --text: #c0caf5;
  --muted: #565f89;
  --income: #9ece6a;
  --expense: #f7768e;
  --accent: #7aa2f7;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px;
  padding-bottom: 24px;
}

.header {
  margin-bottom: 16px;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 12px 0;
}

.tabs {
  display: flex;
  gap: 8px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius);
}

.tab {
  flex: 1;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

.content {
  position: relative;
  min-height: 200px;
}

.panel {
  display: none;
  animation: fade 0.2s ease;
}

.panel.active {
  display: block;
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.balance-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
}

.balance-total {
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--muted);
}

.balance-total .label {
  font-size: 0.85rem;
  color: var(--muted);
}

.balance-total .value {
  font-size: 1.75rem;
  font-weight: 700;
}

.balance-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.95rem;
}

.balance-row .income { color: var(--income); font-weight: 600; }
.balance-row .expense { color: var(--expense); font-weight: 600; }

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 600;
}

.list-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin: -6px 0 10px 0;
}

.btn-sm {
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-sm:active {
  opacity: 0.9;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list li {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.list li .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.list li .amount.income { color: var(--income); font-weight: 600; }
.list li .amount.expense { color: var(--expense); font-weight: 600; }

.list li .meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.debt-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.debt-badge.in {
  background: rgba(158, 206, 106, 0.2);
  color: var(--income);
}

.debt-badge.out {
  background: rgba(247, 118, 142, 0.2);
  color: var(--expense);
}

.repay-btn {
  margin-top: 8px;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  width: 100%;
}

.repay-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.debt-item-clickable {
  cursor: pointer;
}
.debt-item-clickable:active {
  opacity: 0.9;
}

.debt-detail-panel,
.detail-panel {
  margin-top: 12px;
}

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.btn-action {
  flex: 1;
  min-width: 120px;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-action:active {
  opacity: 0.9;
}
.btn-back {
  margin-bottom: 12px;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.9rem;
  cursor: pointer;
}
.debt-detail-header {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.debt-detail-header .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.debt-detail-header .meta { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }

.analytics-block {
  margin-top: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
}
.analytics-title {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0 0 12px 0;
  font-weight: 600;
}
.analytics-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.analytics-col { min-width: 0; }
.analytics-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.analytics-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.85rem;
}
.analytics-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.analytics-list li.muted { color: var(--muted); }
.analytics-list .income { color: var(--income); font-weight: 600; }
.analytics-list .expense { color: var(--expense); font-weight: 600; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  font-size: 0.9rem;
  z-index: 100;
  max-width: 90%;
}

.loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 16px 24px;
  background: var(--surface);
  border-radius: var(--radius);
  z-index: 50;
}
