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

html {
  background: #e5e7eb;
}

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --bg: #f5f5f5;
  --card: #fff;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --radius: 8px;
  --shell-width: 480px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}

.app-auth-loading {
  visibility: hidden;
}

/* ── Layout ────────────────────────────── */

.page { display: none; padding: 16px; padding-bottom: 104px; }
.page.active { display: block; }

.header {
  background: var(--primary);
  color: #fff;
  padding: 16px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10;
}

/* ── Cards ─────────────────────────────── */

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.card-title {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.card-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.card-row .card { min-width: 0; }

.card-row .card {
  padding: 14px 8px;
}

.card-row .card-value {
  font-size: 18px;
}

/* ── Forms ──────────────────────────────── */

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

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

.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* ── Buttons ────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  width: 100%;
  min-height: 44px;
}

.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }

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

/* ── Bottom Nav ─────────────────────────── */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 6px 0;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.bottom-nav .nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0 6px;
  color: var(--text-secondary);
  font-size: 11px;
  border: none;
  background: none;
  cursor: pointer;
}

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

.nav-icon {
  display: inline-flex;
  width: 24px;
  height: 24px;
  margin-bottom: 2px;
}

.nav-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── List ───────────────────────────────── */

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.list-item:last-child { border-bottom: none; border-radius: 0 0 var(--radius) var(--radius); }
.list-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }

.list-item-body { flex: 1; }
.list-item-title { font-size: 16px; font-weight: 500; }
.list-item-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.list-item-trailing { text-align: right; margin-left: 12px; }
.list-item-value { font-size: 18px; font-weight: 600; }
.list-item-type { font-size: 12px; color: var(--text-secondary); }

.amount-positive { color: var(--success); }
.amount-negative { color: var(--danger); }

/* ── Badge ──────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.badge-success { background: #dcfce7; color: var(--success); }
.badge-danger { background: #fef2f2; color: var(--danger); }
.badge-primary { background: #dbeafe; color: var(--primary); }

.member-list-item {
  cursor: pointer;
}

.member-list-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.member-list-title .list-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.load-more {
  margin: 12px 0 0;
}

/* ── Modal ──────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

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

.modal {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

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

.amount-preview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.amount-preview div {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.amount-preview span {
  display: block;
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 2px;
}

.amount-preview strong {
  display: block;
  font-size: 18px;
}

.amount-preview-value { color: var(--text); }

/* ── Toast ──────────────────────────────── */

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show { opacity: 1; }

/* ── Empty state ────────────────────────── */

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ── Login page ─────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--primary);
  position: relative;
}

.login-card {
  background: var(--card);
  border-radius: 12px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 24px;
}

/* ── Footer ─────────────────────────────── */

.site-footer {
  padding: 12px 16px calc(90px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--primary);
}

.site-footer-login {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(16px + env(safe-area-inset-bottom));
  padding: 0 24px;
  color: rgba(255,255,255,0.78);
}

.site-footer-login a:hover {
  color: #fff;
}

/* ── Member detail header ───────────────── */

.member-header {
  background: var(--primary);
  color: #fff;
  padding: 24px 16px;
  margin: -16px -16px 16px;
}

.member-name { font-size: 22px; font-weight: 700; }
.member-phone { font-size: 14px; opacity: 0.8; margin-top: 2px; }
.member-status {
  display: inline-flex;
  margin-top: 8px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.16);
  font-size: 12px;
  font-weight: 600;
}
.member-balance { font-size: 36px; font-weight: 800; margin-top: 8px; }
.member-date { font-size: 12px; opacity: 0.7; margin-top: 4px; }

/* ── Action buttons row ─────────────────── */

.action-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.action-row .btn { flex: 1; }

/* ── Txn type tag ───────────────────────── */

.txn-type {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.txn-line {
  display: flex;
  align-items: center;
  gap: 6px;
}

.txn-action {
  margin-top: 6px;
}

.txn-status {
  display: inline-flex;
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 12px;
}

.type-open { background: #dbeafe; color: var(--primary); }
.type-topup { background: #dcfce7; color: var(--success); }
.type-consume { background: #fef3c7; color: #d97706; }
.type-reverse { background: #f3e8ff; color: #7c3aed; }

@media (min-width: 640px) {
  body {
    max-width: var(--shell-width);
    margin: 0 auto;
    box-shadow: 0 0 0 1px rgba(31,41,55,0.06), 0 24px 64px rgba(31,41,55,0.12);
  }

  .page { padding: 20px; padding-bottom: 104px; }

  .bottom-nav {
    left: 50%;
    right: auto;
    width: 100%;
    max-width: var(--shell-width);
    transform: translateX(-50%);
  }
}
