:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-elevated: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #22c55e;
  --accent-dim: #16a34a;
  --danger: #ef4444;
  --warning: #f59e0b;
  --blue: #3b82f6;
  --purple: #a855f7;
  --border: #334155;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ========== AUTH SCREENS ========== */
.auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  max-width: 480px;
  margin: 0 auto;
  left: 0;
  right: 0;
}

.auth-screen.hidden {
  display: none;
}

.auth-logo {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #166534, #22c55e);
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(34, 197, 94, 0.25);
}

.auth-title {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 32px;
  text-align: center;
}

.auth-form {
  width: 100%;
  max-width: 320px;
}

.auth-form .form-group {
  margin-bottom: 16px;
}

.auth-form label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.auth-form input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.05rem;
  outline: none;
}

.auth-form input:focus {
  border-color: var(--accent);
}

/* PIN dots */
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 24px 0 32px;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  transition: all 0.15s;
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.pin-dot.error {
  background: var(--danger);
  border-color: var(--danger);
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* PIN pad */
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
}

.pin-key {
  aspect-ratio: 1;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
}

.pin-key:active {
  background: var(--bg-elevated);
}

.pin-key.empty {
  background: transparent;
  pointer-events: none;
}

.pin-key.action {
  font-size: 1rem;
  color: var(--text-muted);
}

/* User list on login */
.user-list {
  width: 100%;
  max-width: 320px;
  margin-bottom: 20px;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.user-item:active, .user-item.selected {
  border-color: var(--accent);
}

.user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #052e16;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
}

.user-name {
  font-weight: 600;
  font-size: 1rem;
}

.user-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.auth-link {
  margin-top: 24px;
  text-align: center;
  color: var(--accent);
  font-size: 0.9rem;
  background: none;
  border: none;
  cursor: pointer;
  font-weight: 500;
}

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 12px;
  min-height: 20px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
}

.icon-btn:active {
  background: var(--bg-elevated);
}

/* Main content */
.main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(80px + var(--safe-bottom));
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  gap: 4px;
  cursor: pointer;
}

.nav-item.active {
  color: var(--accent);
}

.nav-item span.icon {
  font-size: 1.35rem;
}

/* Cards & sections */
.section {
  padding: 16px;
}

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 600;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}

.account-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 12px;
}

.account-item:last-child {
  border-bottom: none;
}

.account-item:active {
  background: var(--bg-elevated);
}

.account-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.account-info {
  flex: 1;
  min-width: 0;
}

.account-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-type {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.account-balance {
  font-weight: 700;
  font-size: 1rem;
  text-align: right;
}

.account-balance.negative {
  color: var(--danger);
}

/* Net worth banner */
.net-worth {
  background: linear-gradient(135deg, #166534, #15803d);
  border-radius: var(--radius);
  padding: 20px;
  margin: 16px;
  text-align: center;
}

.net-worth-label {
  font-size: 0.85rem;
  opacity: 0.9;
  margin-bottom: 4px;
}

.net-worth-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

/* Transaction list */
.tx-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.tx-item:last-child {
  border-bottom: none;
}

.tx-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.tx-info {
  flex: 1;
  min-width: 0;
}

.tx-desc {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.tx-amount {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
}

.tx-amount.income {
  color: var(--accent);
}

.tx-amount.expense {
  color: var(--danger);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 10px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn:active {
  opacity: 0.8;
}

.btn-primary {
  background: var(--accent);
  color: #052e16;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-block {
  width: 100%;
}

.fab {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom) + 16px);
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #052e16;
  border: none;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(34, 197, 94, 0.4);
  z-index: 90;
  cursor: pointer;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-card);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.25s ease-out;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.modal h2 {
  font-size: 1.2rem;
  margin-bottom: 16px;
  text-align: center;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

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

.form-row {
  display: flex;
  gap: 10px;
}

.form-row .form-group {
  flex: 1;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions .btn {
  flex: 1;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* Account type colors */
.bg-checking { background: #1e40af; }
.bg-savings { background: #065f46; }
.bg-credit { background: #9a3412; }
.bg-cash { background: #854d0e; }
.bg-investment { background: #5b21b6; }
.bg-other { background: #374151; }

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  z-index: 300;
  transition: transform 0.3s;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Detail view */
.detail-header {
  padding: 20px 16px;
  text-align: center;
}

.detail-balance {
  font-size: 2.2rem;
  font-weight: 800;
  margin: 8px 0;
}

.detail-type {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Hidden pages */
.page {
  display: none;
}

.page.active {
  display: block;
}

/* Stats row */
.stats-row {
  display: flex;
  gap: 10px;
  padding: 0 16px 16px;
}

.stat-card {
  flex: 1;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
}

.stat-value.positive { color: var(--accent); }
.stat-value.negative { color: var(--danger); }

/* Filter chips */
.chips {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  overflow-x: auto;
}

.chip {
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  cursor: pointer;
}

.chip.active {
  background: var(--accent);
  color: #052e16;
  border-color: var(--accent);
  font-weight: 600;
}

/* App content hidden until login */
#app.locked .header,
#app.locked .main,
#app.locked .bottom-nav,
#app.locked .fab {
  display: none !important;
}
