:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --radius: 16px;
  --shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.06);
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 92px;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

/* Top Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}

.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-group {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}

.period-selector-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.period-select {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
}

.member-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.avatar-circle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
}

/* Banners */
.banner {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.banner-warning {
  background: var(--warning-bg);
  border: 1px solid #fde68a;
  color: #92400e;
}

.banner-danger {
  background: var(--danger-bg);
  border: 1px solid #fecaca;
  color: #991b1b;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.hero-card {
  background: linear-gradient(135deg, #312e81 0%, #4f46e5 100%);
  color: #ffffff;
  border: none;
}

.hero-period-dates {
  font-size: 0.8rem;
  opacity: 0.85;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hero-main-stat {
  margin-bottom: 14px;
}

.hero-label {
  font-size: 0.82rem;
  opacity: 0.85;
}

.hero-amount {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-top: 2px;
}

.hero-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 10px;
}

.hero-stat-box {
  display: flex;
  flex-direction: column;
}

.hero-stat-box span:first-child {
  font-size: 0.72rem;
  opacity: 0.85;
}

.hero-stat-box span:last-child {
  font-size: 0.92rem;
  font-weight: 700;
  margin-top: 2px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

/* Quick Add Expense Form */
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

input, select {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.96rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

input:focus, select:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.amount-input-wrap {
  display: flex;
  gap: 6px;
  align-items: center;
}

.amount-input-wrap input {
  font-size: 1.15rem;
  font-weight: 700;
}

.quick-k-btn {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #c7d2fe;
  background: #eef2ff;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

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

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
  border-radius: 8px;
}

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

/* Category Progress */
.cat-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cat-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cat-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

.cat-name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cat-numbers {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.cat-numbers strong {
  color: var(--text);
}

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* Planned Bills & Expenses List */
.list-items {
  display: flex;
  flex-direction: column;
  divide-y: 1px solid var(--border);
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

.list-row:last-child {
  border-bottom: none;
}

.row-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.cat-icon-box {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.row-title {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.row-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.row-amount {
  font-weight: 700;
  font-size: 0.95rem;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.badge-overdue {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge-due_soon {
  background: var(--warning-bg);
  color: #b45309;
}

.badge-upcoming {
  background: var(--surface-alt);
  color: var(--text-muted);
}

.badge-paid {
  background: var(--success-bg);
  color: #047857;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}

.nav-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.nav-tab.active {
  color: var(--primary);
  background: #eef2ff;
}

.nav-icon {
  font-size: 1.2rem;
}

/* Auth & Profile Picker Screen */
.center-screen {
  min-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 18px 0;
}

.profile-tile {
  background: var(--surface-alt);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 18px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.profile-tile:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.profile-tile .avatar-circle {
  width: 48px;
  height: 48px;
  font-size: 1.2rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  padding: 20px;
  box-shadow: 0 20px 35px -5px rgba(0, 0, 0, 0.2);
}
