/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #1a1f2e;
  --bg2:       #222840;
  --bg3:       #2a3050;
  --accent:    #c8a96e;
  --accent2:   #e8c98e;
  --green:     #4caf82;
  --red:       #e05a5a;
  --text:      #e8e8f0;
  --muted:     #8890aa;
  --border:    #333a55;
  --radius:    10px;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 2rem;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

header h1 span { color: var(--text); font-weight: 400; }

nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  transition: all 0.2s;
}
nav a:hover, nav a.active {
  color: var(--accent);
  background: rgba(200,169,110,0.1);
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
main {
  max-width: 680px;
  margin: 0 auto;
  padding: 1.25rem;
}

section { margin-bottom: 1.5rem; }

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

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
}

/* ── Balance Grid ────────────────────────────────────────────────────────── */
.balance-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.balance-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.balance-card .person {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.balance-card .amount {
  font-size: 1.25rem;
  font-weight: 700;
}

.balance-card .label {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.balance-card.positive .amount { color: var(--green); }
.balance-card.negative .amount { color: var(--red); }
.balance-card.zero .amount { color: var(--muted); }

/* ── Settle button ───────────────────────────────────────────────────────── */
.settle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.settle-hint {
  font-size: 0.82rem;
  color: var(--muted);
  flex: 1;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  border: none;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #1a1f2e;
}
.btn-primary:hover { background: var(--accent2); }

.btn-settle {
  background: var(--bg3);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.55rem 1.1rem;
}
.btn-settle:hover { background: rgba(200,169,110,0.15); }

.btn-confirm {
  background: var(--green);
  color: #fff;
}
.btn-confirm:hover { background: #3d9a6f; }

.btn-cancel {
  background: var(--bg3);
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-cancel:hover { color: var(--text); }

.btn-full { width: 100%; }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Add Expense Form ────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 0.9rem;
}

.form-group label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group select,
.form-group input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* ── Expense List ─────────────────────────────────────────────────────────── */
.expense-list { display: flex; flex-direction: column; gap: 0.6rem; }

.expense-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.expense-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg3);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
  color: var(--accent);
}

.expense-meta { flex: 1; min-width: 0; }

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

.expense-who {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

.expense-amount {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.expense-date {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.15rem;
  text-align: right;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1rem;
  font-size: 0.9rem;
}

/* ── Settle Modal ────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

@media (min-width: 480px) {
  .modal-overlay { align-items: center; }
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px 16px 8px 8px;
  width: 100%;
  max-width: 500px;
  padding: 1.5rem;
}

@media (min-width: 480px) {
  .modal { border-radius: 16px; }
}

.modal h2 {
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.modal p.sub {
  font-size: 0.83rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

.txn-list { margin-bottom: 1.25rem; }

.txn-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.txn-item:last-child { border-bottom: none; }

.txn-from { font-weight: 600; color: var(--red); }
.txn-arrow { color: var(--muted); }
.txn-to { font-weight: 600; color: var(--green); }
.txn-amt { margin-left: auto; font-weight: 700; color: var(--accent); }

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.modal-actions .btn { flex: 1; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.toast {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 1.2rem;
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
  animation: toastIn 0.25s ease;
}

.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--red);   color: var(--red);   }

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

/* ── History page ────────────────────────────────────────────────────────── */
.session-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}

.session-header {
  padding: 0.9rem 1.1rem;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.session-header .date {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.session-header .count {
  font-size: 0.75rem;
  color: var(--muted);
}

.session-header .chevron {
  color: var(--muted);
  transition: transform 0.2s;
}

.session-header.open .chevron { transform: rotate(180deg); }

.session-body {
  padding: 1rem 1.1rem;
  border-top: 1px solid var(--border);
  display: none;
}

.session-body.open { display: block; }

.session-txns {
  margin-bottom: 1rem;
}

.session-txns h4 {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.session-expenses h4 {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.session-expense-item {
  font-size: 0.83rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  color: var(--text);
}
.session-expense-item:last-child { border-bottom: none; }

.session-expense-item .who { color: var(--muted); font-size: 0.75rem; }
.session-expense-item .amt { color: var(--accent); font-weight: 600; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .balance-grid { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
  .balance-card { padding: 0.75rem 0.5rem; }
  .balance-card .amount { font-size: 1.05rem; }
  .form-row { grid-template-columns: 1fr; }
}
