/* Portofel — mobile-first design */
:root {
  --primary: #15803D;
  --primary-soft: #22C55E;
  --primary-bg: #DCFCE7;
  --accent: #F59E0B;
  --accent-soft: #FCD34D;
  --bg: #FFFBEB;
  --bg-soft: #FEF3C7;
  --surface: #FFFFFF;
  --text: #1C1917;
  --text-soft: #57534E;
  --text-faint: #A8A29E;
  --border: #E7E5E4;
  --border-soft: #F5F5F4;
  --danger: #DC2626;
  --warning: #D97706;
  --shadow-sm: 0 1px 2px rgba(28,25,23,.05);
  --shadow: 0 2px 8px rgba(28,25,23,.08);
  --shadow-lg: 0 8px 24px rgba(28,25,23,.12);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

a { color: var(--primary); text-decoration: none; }
a:active { opacity: .7; }

/* ── Layout (mobile first) ── */
.shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Reserve bottom space for fixed nav */
  padding-bottom: 72px;
}
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
  width: 100%;
}
main { flex: 1; padding: 16px 0 24px; }

/* ── Top bar (mobile: just brand + logout) ── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.topbar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text);
}
.brand-icon {
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  font-size: 1.1rem;
  box-shadow: var(--shadow-sm);
}
.brand span { font-size: 1rem; }

/* Top nav links: hidden on mobile (use bottom nav instead) */
.nav-links { display: none; }

.nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .85rem;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}
.avatar.sm { width: 22px; height: 22px; font-size: .72rem; }
.avatar.lg { width: 48px; height: 48px; font-size: 1.1rem; }

/* ── Bottom nav (mobile primary navigation) ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 110;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  color: var(--text-soft);
  font-size: .7rem;
  font-weight: 600;
  border-radius: 8px;
  text-decoration: none;
}
.bottom-nav a .nav-icon { font-size: 1.4rem; line-height: 1; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a.fab {
  background: var(--primary);
  color: white;
  font-size: .7rem;
}
.bottom-nav a.fab .nav-icon { font-size: 1.5rem; }
.bottom-nav a.fab.active { background: var(--primary); color: white; }

/* ── Headings ── */
h1 { font-size: 1.5rem; font-weight: 800; margin: 0 0 4px; letter-spacing: -.4px; }
h2 { font-size: 1.05rem; font-weight: 700; margin: 22px 0 10px; letter-spacing: -.2px; color: var(--text); }
h3 { font-size: 1rem; font-weight: 700; margin: 14px 0 6px; }
.page-sub { color: var(--text-soft); margin: 0 0 18px; font-size: .9rem; }
.page-header { margin-bottom: 16px; }

/* ── Tabs (Comun / Total / Personal) ── */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1;
  text-align: center;
  padding: 9px 8px;
  font-weight: 600;
  font-size: .88rem;
  color: var(--text-soft);
  border-radius: 7px;
  white-space: nowrap;
  text-decoration: none;
  transition: background .12s;
}
.tab:active { background: var(--bg-soft); }
.tab.active { background: var(--primary-bg); color: var(--primary); }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
}
.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.card-title { font-weight: 700; font-size: 1rem; margin: 0 0 4px; }
.card-meta { color: var(--text-soft); font-size: .85rem; }

/* ── Form ── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  color: var(--text);
  margin-bottom: 6px;
}
.form-group input[type=text],
.form-group input[type=email],
.form-group input[type=password],
.form-group input[type=number],
.form-group input[type=date],
.form-group input[type=tel],
.form-group input[type=file],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  font-size: 16px; /* prevent iOS zoom */
  color: var(--text);
  transition: border-color .12s, box-shadow .12s;
  -webkit-appearance: none;
  appearance: none;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(34,197,94,.15);
}
.form-help { font-size: .8rem; color: var(--text-faint); margin-top: 4px; }

/* ── Toggle (checkbox styled as card) ── */
.toggle-group { margin: 14px 0; }
.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.toggle-row:active { background: var(--bg-soft); }
.toggle-row input[type=checkbox] {
  width: 22px;
  height: 22px;
  margin: 1px 0 0;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.toggle-content { flex: 1; }
.toggle-title { font-weight: 700; display: block; }
.toggle-help { font-size: .82rem; color: var(--text-soft); display: block; margin-top: 2px; }

/* ── Buttons (touch friendly) ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--primary);
  color: white;
  border: none;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 700;
  font-size: .98rem;
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;
  transition: filter .12s, transform .06s;
  -webkit-appearance: none;
  appearance: none;
}
.btn:active { transform: scale(.98); filter: brightness(.95); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.btn-lg { padding: 16px 22px; font-size: 1.02rem; min-height: 52px; }
.btn.btn-block { width: 100%; }
.btn.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.btn-accent { background: var(--accent); color: var(--text); }
.btn.btn-danger { background: var(--danger); color: white; }

/* ── Flash ── */
.flash {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-weight: 600;
  font-size: .92rem;
}
.flash-success { background: var(--primary-bg); color: var(--primary); border: 1px solid #BBF7D0; }
.flash-error   { background: #FEE2E2; color: var(--danger); border: 1px solid #FECACA; }
.flash-warning { background: #FEF3C7; color: var(--warning); border: 1px solid #FDE68A; }
.flash-info    { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; }
table th, table td { padding: 10px 6px; text-align: left; border-bottom: 1px solid var(--border-soft); font-size: .92rem; }
table th { font-weight: 700; color: var(--text-soft); font-size: .78rem; text-transform: uppercase; letter-spacing: .5px; }

/* ── Stat blocks ── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: .72rem; color: var(--text-soft); text-transform: uppercase; letter-spacing: .8px; font-weight: 700; }
.stat-value { font-size: 1.3rem; font-weight: 800; margin-top: 4px; color: var(--text); line-height: 1.15; }
.stat-value .currency { font-size: .75rem; color: var(--text-soft); font-weight: 600; }
.stat-trend { font-size: .75rem; color: var(--text-soft); margin-top: 2px; }

.stat-grid .stat:first-child { grid-column: 1 / -1; }
.stat-grid .stat:first-child .stat-value { font-size: 1.8rem; }

/* ── Receipt rows ── */
.receipt-row {
  display: flex;
  gap: 12px;
  padding: 14px 10px;
  border-bottom: 1px solid var(--border-soft);
  transition: background .1s;
  border-radius: var(--radius-sm);
  align-items: center;
  text-decoration: none;
  color: inherit;
}
.receipt-row:last-child { border-bottom: 0; }
.receipt-row:active { background: var(--bg-soft); }
.receipt-row .r-icon {
  width: 46px; height: 46px;
  border-radius: 12px;
  background: var(--primary-bg);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}
.receipt-row .r-info { flex: 1; min-width: 0; }
.receipt-row .r-store { font-weight: 700; font-size: 1rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.receipt-row .r-meta { font-size: .78rem; color: var(--text-soft); display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; align-items: center; }
.receipt-row .r-amount { font-weight: 800; font-size: 1.05rem; color: var(--text); white-space: nowrap; }

/* ── Categories bar ── */
.cat-bar { display: flex; flex-direction: column; gap: 12px; }
.cat-row { display: flex; flex-direction: column; gap: 4px; }
.cat-row .cat-info { display: flex; justify-content: space-between; align-items: center; }
.cat-row .cat-name { font-weight: 600; font-size: .9rem; }
.cat-row .cat-amt { font-weight: 700; font-size: .9rem; }
.cat-row .cat-bar-track { height: 8px; background: var(--border-soft); border-radius: 4px; overflow: hidden; }
.cat-row .cat-bar-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width .3s; }

/* ── Receipt upload ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 16px;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
  display: block;
  transition: border-color .12s, background .12s;
}
.upload-zone:active, .upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-bg);
}
.upload-zone .upload-icon { font-size: 3rem; }
.upload-zone .upload-text { font-weight: 700; margin: 8px 0 4px; font-size: 1rem; }
.upload-zone .upload-help { color: var(--text-soft); font-size: .82rem; }
.upload-preview {
  margin-top: 14px;
  max-width: 100%;
  max-height: 280px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* ── Item rows ── */
.item-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
  align-items: center;
}
.item-row:last-child { border-bottom: 0; }
.item-row .item-name { font-weight: 600; font-size: .95rem; }
.item-row .item-cat { font-size: .75rem; color: var(--text-soft); margin-top: 2px; }
.item-row .item-total { font-weight: 700; white-space: nowrap; }

/* ── Auth pages ── */
.auth-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-soft) 100%);
}
.auth-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 28px 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.auth-card h1 { text-align: center; margin-bottom: 4px; }
.auth-card .auth-sub { text-align: center; color: var(--text-soft); margin-bottom: 22px; font-size: .95rem; }
.auth-card .brand { justify-content: center; margin-bottom: 14px; font-size: 1.3rem; }
.auth-card .brand-icon { width: 48px; height: 48px; font-size: 1.5rem; border-radius: 12px; }

/* ── Chip ── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--border-soft);
  color: var(--text);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 600;
}
.chip.green { background: var(--primary-bg); color: var(--primary); }
.chip.amber { background: var(--bg-soft); color: var(--accent); }
.chip.red { background: #FEE2E2; color: var(--danger); }
.chip.gray { background: var(--border-soft); color: var(--text-soft); }

/* ── Member row ── */
.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}
.member-row:last-child { border-bottom: 0; }

/* ── Invite box ── */
.invite-box {
  background: var(--primary-bg);
  border: 2px dashed var(--primary);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

footer {
  border-top: 1px solid var(--border);
  padding: 14px 0;
  text-align: center;
  font-size: .78rem;
  color: var(--text-faint);
  margin-bottom: 72px; /* clear bottom nav */
}

/* ── Desktop (>= 720px): keep mobile-feel but add top nav, drop bottom nav ── */
@media (min-width: 720px) {
  body { font-size: 15px; }
  .shell { padding-bottom: 0; }
  .nav-links { display: flex; gap: 14px; align-items: center; }
  .nav-links a {
    color: var(--text-soft); font-weight: 600;
    padding: 6px 10px; border-radius: 6px; font-size: .9rem;
    text-decoration: none;
  }
  .nav-links a:hover { background: var(--border-soft); color: var(--text); }
  .nav-links a.active { background: var(--primary-bg); color: var(--primary); }
  .bottom-nav { display: none; }
  footer { margin-bottom: 0; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .stat-grid .stat:first-child { grid-column: auto; }
  .stat-grid .stat:first-child .stat-value { font-size: 1.4rem; }
  h1 { font-size: 1.7rem; }
  .brand span { font-size: 1.1rem; }
  .brand-icon { width: 36px; height: 36px; font-size: 1.2rem; }
}
