:root {
  --bg: #0f0f11;
  --bg-card: #1a1a1e;
  --bg-input: #25252b;
  --text: #e8e8ed;
  --text-secondary: #8e8ea0;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f59e0b;
  --border: #2a2a30;
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===== AUTH PAGE ===== */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.auth-box {
  width: 100%; max-width: 400px;
}
.auth-logo {
  text-align: center; margin-bottom: 32px;
}
.auth-logo h1 { font-size: 28px; font-weight: 700; }
.auth-logo p { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }
.auth-tabs {
  display: flex; gap: 0; margin-bottom: 24px;
  background: var(--bg-input); border-radius: var(--radius-sm); padding: 4px;
}
.auth-tab {
  flex: 1; padding: 10px; text-align: center; border: none;
  background: transparent; color: var(--text-secondary); font-size: 14px;
  font-weight: 500; border-radius: 6px; cursor: pointer; transition: 0.2s;
}
.auth-tab.active { background: var(--accent); color: white; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form input {
  width: 100%; padding: 12px 16px; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 15px; outline: none; transition: 0.2s;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-form .btn {
  width: 100%; padding: 12px; background: var(--accent); color: white;
  border: none; border-radius: var(--radius-sm); font-size: 15px;
  font-weight: 600; cursor: pointer; transition: 0.2s;
}
.auth-form .btn:hover { background: var(--accent-hover); }
.auth-form .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-error { color: var(--red); font-size: 13px; text-align: center; padding: 8px; background: rgba(239,68,68,0.1); border-radius: var(--radius-sm); display: none; }

/* ===== MAIN APP ===== */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg); padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding-top: calc(var(--safe-top) + 12px);
}
.app-header h1 { font-size: 18px; font-weight: 700; }
.app-header .user-badge {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.app-header .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center;
  justify-content: center; font-size: 14px; font-weight: 600;
}
.app-header .logout-btn {
  background: none; border: 1px solid var(--border);
  color: var(--text-secondary); padding: 6px 12px; border-radius: 6px;
  font-size: 12px; cursor: pointer;
}

/* Balance card */
.balance-card {
  background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
  border-radius: var(--radius); padding: 20px; margin: 16px;
  position: relative; overflow: hidden;
}
.balance-card::after {
  content: ''; position: absolute; top: -50%; right: -20%;
  width: 200px; height: 200px; border-radius: 50%;
  background: rgba(255,255,255,0.05); pointer-events: none;
}
.balance-card small { font-size: 12px; opacity: 0.8; display: block; margin-bottom: 4px; }
.balance-card .amount { font-size: 32px; font-weight: 700; }
.balance-card .stats-row { display: flex; gap: 24px; margin-top: 16px; }
.balance-card .stat-item { font-size: 13px; }
.balance-card .stat-item span { display: block; font-weight: 600; font-size: 16px; margin-top: 2px; }

/* Quick actions */
.quick-actions {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin: 0 16px 16px;
}
.qa-btn {
  padding: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text); font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: 0.2s;
}
.qa-btn:hover { border-color: var(--accent); background: var(--bg-input); }
.qa-btn.primary { background: var(--accent); border-color: var(--accent); }
.qa-btn.primary:hover { background: var(--accent-hover); }

/* Transaction list */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
}
.section-header h2 { font-size: 16px; font-weight: 600; }
.section-header .filter-btn {
  background: none; border: 1px solid var(--border); color: var(--text-secondary);
  padding: 6px 12px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.tx-list { display: flex; flex-direction: column; gap: 1px; padding: 0 16px 80px; }
.tx-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; background: var(--bg-card); border-radius: 4px;
  position: relative; cursor: pointer; transition: 0.2s;
}
.tx-item:hover { background: var(--bg-input); }
.tx-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.tx-info { flex: 1; min-width: 0; }
.tx-category { font-size: 14px; font-weight: 500; }
.tx-notes { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-right { text-align: right; }
.tx-amount { font-size: 15px; font-weight: 600; }
.tx-date { font-size: 11px; color: var(--text-secondary); }
.tx-item.income .tx-amount { color: var(--green); }
.tx-item.expense .tx-amount { color: var(--red); }
.tx-empty {
  text-align: center; padding: 40px 16px; color: var(--text-secondary); font-size: 14px;
}

/* Filters bar */
.filter-bar {
  display: flex; gap: 8px; padding: 0 16px 12px; overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-secondary); font-size: 12px;
  white-space: nowrap; cursor: pointer; transition: 0.2s;
}
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: white; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  z-index: 200; display: none; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto;
  padding: 20px 20px calc(var(--safe-bottom) + 20px);
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal h2 { font-size: 18px; font-weight: 600; margin-bottom: 20px; }
.modal-close {
  position: absolute; top: 12px; right: 16px; background: none; border: none;
  color: var(--text-secondary); font-size: 24px; cursor: pointer;
}
.modal .form-group { margin-bottom: 16px; }
.modal label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 12px; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; outline: none;
}
.modal input:focus, .modal select:focus { border-color: var(--accent); }
.modal textarea { resize: vertical; min-height: 60px; font-family: inherit; }
.modal .btn-submit {
  width: 100%; padding: 12px; background: var(--accent); color: white;
  border: none; border-radius: var(--radius-sm); font-size: 15px;
  font-weight: 600; cursor: pointer;
}
.modal .btn-submit:hover { background: var(--accent-hover); }
.modal .btn-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 20px;
  font-size: 14px; z-index: 300; box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  display: none; animation: fadeIn 0.2s ease; white-space: nowrap;
}
.toast.show { display: block; }
.toast.error { border-color: var(--red); }
.toast.success { border-color: var(--green); }
@keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--bg-card); border-top: 1px solid var(--border);
  display: flex; padding-bottom: var(--safe-bottom);
}
.bottom-nav a {
  flex: 1; text-align: center; padding: 8px 4px;
  color: var(--text-secondary); text-decoration: none;
  font-size: 10px; transition: 0.2s;
}
.bottom-nav a.active { color: var(--accent); }
.bottom-nav .nav-icon { display: block; font-size: 20px; margin-bottom: 2px; }

/* Responsive */
@media (min-width: 600px) {
  .app-container { max-width: 600px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); min-height: 100vh; }
  .auth-page .auth-box { padding: 40px; background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); }
}
