/* ---- Reset + base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: #1a1a1a;
  background: #f5f4f0;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

/* iOS safe area */
#app {
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 480px;
  margin: 0 auto;
}

h1, h2, h3 { font-weight: 600; }
.muted { color: #888; }

/* ---- Screen system ---- */
#app { position: relative; }
.screen { display: none; min-height: 100vh; flex-direction: column; }
.screen.active { display: flex; }

/* ---- Splash ---- */
.splash {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; gap: 24px;
}
.logo-mark {
  width: 56px; height: 56px; border-radius: 16px;
  background: #1a3d2a; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 700; font-family: Georgia, serif;
}
.logo-mark.big { width: 80px; height: 80px; font-size: 40px; border-radius: 22px; }

/* ---- Spinner ---- */
.spinner {
  width: 20px; height: 20px; border: 2.5px solid rgba(26,61,42,0.2);
  border-top-color: #1a3d2a; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner.big { width: 36px; height: 36px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Sign-in screen ---- */
.signin-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 32px; text-align: center; gap: 20px;
}
.signin-wrap h1 { font-size: 26px; }
.signin-wrap p { max-width: 300px; }
.btn-lg { margin-top: 20px; padding: 14px 28px; font-size: 16px; }

/* ---- App header (home screen) ---- */
.app-header {
  background: #1a3d2a; color: #fff;
  padding: 20px 20px 24px;
}
.header-row { display: flex; justify-content: space-between; align-items: flex-start; }
.app-title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.header-sub { font-size: 12px; color: rgba(255,255,255,0.6); margin-top: 2px; }

.total-display { margin-top: 18px; display: flex; align-items: baseline; gap: 12px; }
.total-label { font-size: 12px; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: 0.08em; }
.total-value { font-size: 38px; font-weight: 300; letter-spacing: -0.02em; }

.card-totals-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.card-total-pill {
  flex: 1;
  background: rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.card-total-pill.light {
  background: #fff;
}
.card-pill-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.5);
  font-weight: 600;
}
.card-total-pill.light .card-pill-label {
  color: #888;
}
.card-pill-amount {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}
.card-total-pill.light .card-pill-amount {
  color: #1a1a1a;
}
.summary-card-row {
  margin-bottom: 20px;
}

.action-row { margin-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px; border-radius: 12px; border: none; cursor: pointer;
  font-size: 15px; font-weight: 500; font-family: inherit;
}
.action-btn.primary { background: #fff; color: #1a3d2a; }
.action-btn.secondary { background: rgba(255,255,255,0.12); color: #fff; }
.action-btn:active { transform: scale(0.98); }
.scan-sub { font-size: 11px; opacity: 0.7; margin-left: 6px; }

/* ---- Modal / non-home header ---- */
.modal-header {
  background: #fff; border-bottom: 1px solid #eae8e0;
  padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.modal-header h2 { font-size: 17px; font-weight: 600; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: none; background: transparent;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: currentColor;
}
.icon-btn:active { background: rgba(0,0,0,0.05); }
.app-header .icon-btn { color: rgba(255,255,255,0.8); }

/* ---- App body ---- */
.app-body { flex: 1; padding: 16px 20px 32px; }

.section-header-row {
  display: flex; justify-content: space-between; align-items: center;
  margin: 8px 0 12px;
}
.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: #888; }

.text-btn {
  background: transparent; border: none; color: #1a3d2a; font-size: 14px; font-weight: 500;
  cursor: pointer; padding: 4px 8px; font-family: inherit;
}
.text-btn.muted { color: #888; }
.text-btn:active { opacity: 0.6; }

/* ---- Expense cards ---- */
.expenses-list { display: flex; flex-direction: column; gap: 8px; }

.expense-card {
  background: #fff; border-radius: 12px; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
}
.expense-icon {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.expense-info { flex: 1; min-width: 0; }
.expense-merchant { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-meta { font-size: 12px; color: #888; margin-top: 2px; }
.expense-amount { font-size: 15px; font-weight: 600; flex-shrink: 0; }

.expense-link {
  color: #1a3d2a; font-size: 11px; text-decoration: none; margin-left: 6px;
}

.empty-state {
  text-align: center; padding: 40px 20px; color: #aaa; font-size: 14px;
}

/* ---- Footer ---- */
.app-footer { text-align: center; padding: 20px; }

/* ---- Buttons ---- */
.btn {
  display: inline-block; padding: 11px 18px; border-radius: 10px; cursor: pointer;
  border: none; font-size: 15px; font-weight: 500; font-family: inherit; text-align: center;
  text-decoration: none;
}
.btn-primary { background: #1a3d2a; color: #fff; }
.btn-primary:active { background: #0f2a1c; }
.btn-secondary { background: #eae8e0; color: #1a1a1a; }
.btn-secondary:active { background: #dcd9ce; }

/* ---- Form ---- */
.form { display: flex; flex-direction: column; gap: 14px; padding-top: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: #888; }
.field input, .field select {
  width: 100%; padding: 12px 14px;
  border: 1px solid #e0ddd3; border-radius: 10px; background: #fff;
  font-size: 16px; font-family: inherit; color: #1a1a1a;
  -webkit-appearance: none; appearance: none;
}
.field input:focus, .field select:focus {
  outline: none; border-color: #1a3d2a;
}
.field select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 40px;
}

.form-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 8px; }

/* ---- Review screen preview ---- */
.review-preview {
  width: 100%; max-height: 180px; overflow: hidden; border-radius: 12px;
  margin-bottom: 14px; background: #eae8e0;
}
.review-preview img { width: 100%; height: 180px; object-fit: cover; display: block; }
.review-preview.hidden { display: none; }

/* ---- Summary ---- */
.summary-totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.summary-total-card {
  background: #fff; border-radius: 12px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.summary-total-card .muted { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; }
.summary-total-value { font-size: 22px; font-weight: 600; }

.cat-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid #eae8e0;
}
.cat-row:last-child { border-bottom: none; }
.cat-emoji { font-size: 18px; width: 28px; text-align: center; }
.cat-name { flex: 1; font-size: 14px; }
.cat-bar-wrap {
  flex: 1; height: 6px; background: #eae8e0; border-radius: 3px; overflow: hidden; max-width: 120px;
}
.cat-bar { height: 100%; border-radius: 3px; }
.cat-amount { font-size: 14px; font-weight: 600; width: 70px; text-align: right; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: #1a1a1a; color: #fff; padding: 12px 20px; border-radius: 24px;
  font-size: 14px; z-index: 1000; pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
  opacity: 0; max-width: 90%; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { background: #8b2323; }

/* ---- Overlay ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(26,61,42,0.92); color: #fff;
  display: none; align-items: center; justify-content: center; z-index: 900;
  padding: 20px;
}
.overlay.show { display: flex; }
.overlay-inner { text-align: center; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.overlay .spinner { border-color: rgba(255,255,255,0.2); border-top-color: #fff; }
.overlay p { font-size: 15px; color: rgba(255,255,255,0.9); }
