:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-card: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #666666;
  --accent: #5865f2;
  --accent-light: #7289da;
  --green: #2ecc71;
  --red: #e74c3c;
  --orange: #f39c12;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0a0;
  --border: #2a2a4a;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  min-height: 100vh;
  padding-bottom: 80px;
}

/* Header */
.header {
  background: var(--accent);
  color: white;
  padding: 16px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px rgba(88,101,242,0.3);
}

.header h1 {
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.header-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.header-btn:hover {
  background: rgba(255,255,255,0.3);
}

/* Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  border: none;
  background: none;
}

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

.nav-item .icon {
  font-size: 22px;
  margin-bottom: 2px;
}

.nav-item.add-btn .icon {
  background: var(--accent);
  color: white;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-top: -20px;
  box-shadow: 0 4px 12px rgba(88,101,242,0.4);
}

/* Pages */
.page {
  display: none;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.card-clickable {
  cursor: pointer;
}

/* Balance Overview */
.balance-overview {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: white;
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  text-align: center;
}

.balance-amount {
  font-size: 36px;
  font-weight: 700;
  margin: 8px 0;
}

.balance-label {
  font-size: 14px;
  opacity: 0.9;
}

.balance-row {
  display: flex;
  justify-content: space-around;
  margin-top: 16px;
}

.balance-col {
  text-align: center;
}

.balance-col .label {
  font-size: 12px;
  opacity: 0.8;
}

.balance-col .value {
  font-size: 20px;
  font-weight: 600;
  margin-top: 4px;
}

.balance-col .value.green { color: #a8ffc4; }
.balance-col .value.red { color: #ffb3b3; }

/* Debt List */
.debt-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.debt-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  margin-right: 12px;
  flex-shrink: 0;
}

.debt-info {
  flex: 1;
}

.debt-name {
  font-weight: 600;
  font-size: 15px;
}

.debt-detail {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.debt-amount {
  font-weight: 700;
  font-size: 16px;
}

.debt-amount.positive { color: var(--green); }
.debt-amount.negative { color: var(--red); }

/* Group Cards */
.group-card {
  display: flex;
  align-items: center;
  gap: 14px;
}

.group-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.group-info {
  flex: 1;
}

.group-name {
  font-weight: 600;
  font-size: 16px;
}

.group-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.group-balance {
  text-align: right;
}

.group-balance-amount {
  font-weight: 700;
  font-size: 16px;
}

/* Expense List */
.expense-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.expense-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.expense-info {
  flex: 1;
}

.expense-desc {
  font-weight: 600;
  font-size: 15px;
}

.expense-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.expense-amount-col {
  text-align: right;
}

.expense-total {
  font-weight: 700;
  font-size: 16px;
}

.expense-your-share {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: var(--transition);
  outline: none;
}

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

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

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

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

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

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

.btn-outline {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 14px;
}

/* Chips */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  border: 2px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: var(--transition);
}

.chip.active, .chip:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

/* Category Grid */
.category-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.category-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 2px solid transparent;
  background: var(--bg-secondary);
  transition: var(--transition);
  font-size: 12px;
  text-align: center;
}

.category-item:hover, .category-item.active {
  border-color: var(--accent);
  background: rgba(88,101,242,0.1);
}

.category-item .cat-icon {
  font-size: 24px;
}

/* Split Options */
.split-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 2px solid var(--border);
  margin-bottom: 8px;
  transition: var(--transition);
}

.split-option:hover, .split-option.active {
  border-color: var(--accent);
  background: rgba(88,101,242,0.05);
}

.split-option .icon {
  font-size: 24px;
}

.split-option .label {
  font-weight: 600;
}

.split-option .desc {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Member Select */
.member-checkbox {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.member-checkbox:hover {
  background: var(--bg-secondary);
}

.member-checkbox input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-primary);
  border-radius: 16px 16px 0 0;
  padding: 24px;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
}

/* Section */
.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 20px 0 10px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state .emoji {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 16px;
  margin-bottom: 16px;
}

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

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

/* Simplify Visual */
.simplify-arrow {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.simplify-from, .simplify-to {
  font-weight: 600;
  font-size: 14px;
}

.simplify-arrow-icon {
  font-size: 20px;
  color: var(--accent);
}

.simplify-amount {
  margin-left: auto;
  font-weight: 700;
  color: var(--accent);
}

/* Settings */
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

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

.settings-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-icon {
  font-size: 22px;
}

.settings-label {
  font-weight: 500;
}

.settings-value {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Language Switch */
.lang-switch {
  display: flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--accent);
}

.lang-btn {
  padding: 10px 20px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  transition: var(--transition);
}

.lang-btn.active {
  background: var(--accent);
  color: white;
}

/* Tabs */
.tabs {
  display: flex;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: var(--transition);
  border: none;
  background: none;
  color: var(--text-secondary);
}

.tab.active {
  background: var(--accent);
  color: white;
}

/* Loading */
.loading {
  text-align: center;
  padding: 32px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive */
@media (min-width: 600px) {
  .page {
    max-width: 500px;
    margin: 0 auto;
  }
}

/* Participants split input */
.participant-split-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.participant-split-row .name {
  flex: 1;
  font-weight: 500;
}

.participant-split-row input {
  width: 100px;
  padding: 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  text-align: right;
}

.participant-split-row input:focus {
  border-color: var(--accent);
  outline: none;
}

/* Group detail view */
.group-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.group-header-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

.group-header-info h2 {
  font-size: 22px;
}

.group-header-info .meta {
  color: var(--text-secondary);
  font-size: 14px;
}

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

/* Invite code */
.invite-code {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  font-family: monospace;
  font-size: 20px;
  letter-spacing: 2px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
}
