:root {
  --green: #1CC29F;
  --green-dark: #17a88a;
  --green-light: #e8f8f4;
  --red: #FF6B6B;
  --red-light: #fff0f0;
  --bg: #ffffff;
  --bg-alt: #F7F7F7;
  --bg-card: #ffffff;
  --text: #2d3748;
  --text-secondary: #718096;
  --text-muted: #a0aec0;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.07), 0 4px 6px rgba(0,0,0,0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 50px;
  --sidebar-w: 240px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

html { font-size: 16px; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-alt);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; min-height: 100vh; }

/* ---- SIDEBAR (DESKTOP) ---- */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-w); height: 100vh;
  background: var(--bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 100;
  transition: transform .2s;
}
.sidebar.hidden { display: none; }

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 24px 20px 20px;
  font-weight: 700; font-size: 1.15rem; color: var(--text);
}
.sidebar-logo { flex-shrink: 0; }

.sidebar-nav {
  list-style: none; flex: 1; padding: 0 12px;
}
.sidebar-nav li a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none;
  font-weight: 500; font-size: .93rem;
  transition: background .15s, color .15s;
}
.sidebar-nav li a:hover { background: var(--bg-alt); color: var(--text); }
.sidebar-nav li a.active { background: var(--green-light); color: var(--green); font-weight: 600; }
.nav-icon { font-size: 1.1rem; width: 24px; text-align: center; }

.nav-spacer { flex: 1; }
.sidebar-nav li a.nav-logout { color: #c53030; }
.sidebar-nav li a.nav-logout:hover { background: var(--red-light); color: #c53030; }
.tab-item.tab-logout { color: #c53030; }
.tab-item.tab-logout.active { color: #c53030; }

/* ---- BOTTOM BAR (MOBILE) ---- */
.bottom-bar {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg); border-top: 1px solid var(--border);
  justify-content: space-around; align-items: center;
  height: 60px; z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-bar.hidden { display: none !important; }
.tab-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-decoration: none; color: var(--text-muted);
  font-size: .68rem; font-weight: 500;
  padding: 6px 0; min-width: 52px;
  transition: color .15s;
}
.tab-item.active { color: var(--green); }
.tab-icon { font-size: 1.2rem; }

/* ---- MAIN CONTENT ---- */
.main-content {
  flex: 1; margin-left: var(--sidebar-w);
  padding: 32px; max-width: 900px;
  width: calc(100% - var(--sidebar-w));
}
.main-content.full-width {
  margin-left: 0; width: 100%;
  max-width: 480px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}

/* ---- TYPOGRAPHY ---- */
h1 { font-size: 1.65rem; font-weight: 700; margin-bottom: 4px; }
h2 { font-size: 1.3rem; font-weight: 600; margin-bottom: 4px; }
h3 { font-size: 1.05rem; font-weight: 600; }
.page-header { margin-bottom: 24px; }
.page-header p { color: var(--text-secondary); font-size: .9rem; }

/* ---- CARDS ---- */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
  margin-bottom: 16px;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 22px; border-radius: var(--radius-pill);
  font-family: var(--font); font-weight: 600; font-size: .88rem;
  border: none; cursor: pointer; text-decoration: none;
  transition: background .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); box-shadow: var(--shadow-md); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #e55a5a; }
.btn-outline {
  background: transparent; color: var(--text-secondary);
  border: 1.5px solid var(--border);
}
.btn-outline:hover { border-color: var(--text-secondary); color: var(--text); }
.btn-sm { padding: 7px 16px; font-size: .82rem; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--green); padding: 6px 12px; }
.btn-ghost:hover { background: var(--green-light); }

/* ---- FORMS ---- */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-weight: 500; font-size: .85rem;
  margin-bottom: 6px; color: var(--text-secondary);
}
.form-control {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font); font-size: .92rem; color: var(--text);
  background: var(--bg); transition: border-color .15s;
  outline: none;
}
.form-control:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(28,194,159,.12); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23718096' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
textarea.form-control { resize: vertical; min-height: 70px; }

/* ---- AUTH PAGE ---- */
.auth-card {
  width: 100%; background: var(--bg-card);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}
.auth-card .auth-logo {
  display: flex; align-items: center; gap: 10px;
  justify-content: center; margin-bottom: 28px;
}
.auth-card .auth-logo span { font-size: 1.3rem; font-weight: 700; }
.auth-card h2 { text-align: center; margin-bottom: 24px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: .88rem; color: var(--text-secondary); }
.auth-footer a { color: var(--green); text-decoration: none; font-weight: 600; }
.auth-footer a:hover { text-decoration: underline; }

/* ---- HERO BALANCE ---- */
.hero-balance {
  text-align: center; padding: 28px 20px;
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 24px;
}
.hero-balance .balance-label { font-size: .85rem; color: var(--text-secondary); margin-bottom: 4px; }
.hero-balance .balance-amount { font-size: 2.2rem; font-weight: 700; }
.hero-balance .balance-row { display: flex; justify-content: center; gap: 32px; margin-top: 12px; }
.hero-balance .balance-sub { font-size: .85rem; }
.balance-positive { color: var(--green); }
.balance-negative { color: var(--red); }
.balance-zero { color: var(--text-muted); }

/* ---- AVATAR ---- */
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; color: #fff;
  flex-shrink: 0; text-transform: uppercase;
}
.avatar-sm { width: 32px; height: 32px; font-size: .72rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.1rem; }

/* ---- LIST ITEMS ---- */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit;
  transition: background .12s; cursor: pointer;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--bg-alt); }
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: .93rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub { font-size: .8rem; color: var(--text-secondary); }
.list-item-right { text-align: right; flex-shrink: 0; }
.list-item-amount { font-weight: 700; font-size: .95rem; }

/* ---- EXPENSE ROW ---- */
.expense-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.expense-row:last-child { border-bottom: none; }
.expense-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--bg-alt); display: flex; align-items: center;
  justify-content: center; font-size: 1.2rem; flex-shrink: 0;
}
.expense-body { flex: 1; min-width: 0; }
.expense-desc { font-weight: 600; font-size: .93rem; }
.expense-meta { font-size: .78rem; color: var(--text-secondary); }
.expense-amount { text-align: right; font-weight: 700; font-size: .95rem; flex-shrink: 0; }

/* ---- SPLIT ROWS ---- */
.split-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.split-row:last-child { border-bottom: none; }
.split-row .form-control { flex: 1; }
.split-row .split-name { flex: 1; font-weight: 500; font-size: .9rem; min-width: 80px; }
.split-row .split-amount { width: 100px; text-align: right; }

/* ---- ACTIVITY ITEM ---- */
.activity-item {
  display: flex; gap: 12px; padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
}
.activity-icon.expense-add { background: var(--green-light); }
.activity-icon.expense-edit { background: #FFF3E0; }
.activity-icon.expense-delete { background: var(--red-light); }
.activity-icon.settlement { background: #E3F2FD; }
.activity-body { flex: 1; }
.activity-text { font-size: .9rem; }
.activity-text strong { font-weight: 600; }
.activity-time { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

/* ---- MEMBER CHIPS ---- */
.member-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.member-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px 4px 4px; border-radius: var(--radius-pill);
  background: var(--bg-alt); font-size: .82rem; font-weight: 500;
}
.member-chip .avatar { width: 26px; height: 26px; font-size: .65rem; }

/* ---- EMPTY STATE ---- */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--text-secondary);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: .5; }
.empty-state p { font-size: .95rem; }

/* ---- BADGE ---- */
.badge {
  display: inline-block; padding: 2px 10px;
  border-radius: var(--radius-pill); font-size: .72rem;
  font-weight: 600; text-transform: uppercase;
}
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }

/* ---- TOAST ---- */
.toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 20px; border-radius: var(--radius-sm);
  font-size: .88rem; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: slideIn .25s ease;
  max-width: 360px;
}
.toast-success { background: var(--green); color: #fff; }
.toast-error { background: var(--red); color: #fff; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---- DETAIL HEADER ---- */
.detail-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 24px;
}
.detail-header .back-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-alt); border: none; cursor: pointer;
  font-size: 1.1rem; color: var(--text-secondary);
  transition: background .15s;
}
.detail-header .back-btn:hover { background: var(--border); }
.detail-title { flex: 1; }

/* ---- ACTIONS ---- */
.action-bar {
  display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap;
}

/* ---- MODAL OVERLAY ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 24px;
}
.modal {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 28px;
  width: 100%; max-width: 480px; max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar { display: none !important; }
  .sidebar.hidden { display: none !important; }
  .bottom-bar { display: flex !important; }
  .bottom-bar.hidden { display: none !important; }
  .main-content {
    margin-left: 0; width: 100%; padding: 20px 16px;
    padding-bottom: 80px; max-width: 100%;
  }
  .main-content.full-width { padding-bottom: 24px; }
  .hero-balance .balance-amount { font-size: 1.7rem; }
  h1 { font-size: 1.35rem; }
  .action-bar { flex-direction: column; }
  .action-bar .btn { width: 100%; }
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ---- LOADING ---- */
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--green); border-radius: 50%;
  animation: spin .6s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- UTILITIES ---- */
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.hidden { display: none; }

.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-secondary); font-size: .88rem; font-weight: 500;
  text-decoration: none; cursor: pointer; background: none; border: none;
  font-family: var(--font); padding: 0; margin-bottom: 12px;
  transition: color .15s;
}
.back-link:hover { color: var(--green); }

.group-iou-sub {
  font-size: .8rem; margin-top: 2px;
}
