:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --ink: #23302c;
  --muted: #6f7b74;
  --line: #e4ded2;
  --teal: #1f6f5c;
  --teal-dark: #164f42;
  --sand: #e8dfd0;
  --coral: #d9714e;
  --danger: #b3492f;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

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

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--teal) 0%, var(--teal-dark) 100%);
  color: #fff;
}
.login-logo {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  box-shadow: 0 12px 28px rgba(0,0,0,0.25);
  margin-bottom: 16px;
}
.login-mark {
  font-family: ui-serif, Georgia, serif;
  font-size: 30px;
  letter-spacing: 0.08em;
  margin-bottom: 32px;
  opacity: 0.9;
}
.login-card {
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.18);
}
.login-card input {
  width: 100%;
  padding: 14px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 16px;
  margin-bottom: 12px;
}
.login-card button {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: none;
  background: var(--teal);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
.login-error { color: var(--danger); font-size: 13px; margin-bottom: 10px; min-height: 16px; }

/* ---------- Header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 16px 18px 12px;
}
.topbar-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}
.topbar h1 { font-size: 22px; color: var(--teal-dark); }
.topbar .eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 2px;
}
.logout-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 20px;
  margin-bottom: 2px;
}
.logout-btn:active { background: var(--bg); }

/* ---------- Content ---------- */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(90px + var(--safe-bottom));
}

/* ---------- Dashboard ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}
.stat-card .icon-badge {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  margin-bottom: 10px;
}
.stat-card.c-travel .icon-badge { background: #e4eef0; color: #2a7a8c; }
.stat-card.c-airbnb .icon-badge { background: #ece3f5; color: #7856a8; }
.stat-card.c-medicine .icon-badge { background: #fdece3; color: var(--coral); }
.stat-card.c-scans .icon-badge { background: #e7f1e5; color: #4c8a4a; }
.stat-card .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stat-card .value { font-size: 21px; font-weight: 700; color: var(--teal-dark); margin-top: 3px; }
.stat-card .count { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat-card .next-date { font-size: 11px; color: var(--coral); margin-top: 6px; font-weight: 600; }

.stat-card.total {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
  color: #fff;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stat-card.total::after {
  content: '';
  position: absolute;
  right: -30px;
  top: -30px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
}
.stat-card.total .label { color: rgba(255,255,255,0.75); }
.stat-card.total .value { color: #fff; font-size: 32px; margin-top: 6px; }
.stat-card.total .total-icon {
  font-size: 30px;
  opacity: 0.85;
}

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 20px 0 10px;
}

.upcoming-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.upcoming-date {
  background: var(--sand);
  color: var(--teal-dark);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  min-width: 52px;
}
.upcoming-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.upcoming-icon.c-travel { background: #e4eef0; color: #2a7a8c; }
.upcoming-icon.c-airbnb { background: #ece3f5; color: #7856a8; }
.upcoming-icon.c-medicine { background: #fdece3; color: var(--coral); }
.upcoming-icon.c-scans { background: #e7f1e5; color: #4c8a4a; }
.upcoming-info { flex: 1; min-width: 0; }
.upcoming-type { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.upcoming-label { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upcoming-cost { font-weight: 700; color: var(--coral); white-space: nowrap; }

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

/* ---------- Data cards (list views) ---------- */
.data-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  position: relative;
}
.data-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.data-card-title { font-size: 16px; font-weight: 700; color: var(--ink); }
.data-card-date { font-size: 12px; color: var(--muted); margin-top: 2px; }
.data-card-cost { font-size: 16px; font-weight: 700; color: var(--coral); white-space: nowrap; }
.data-card-detail { font-size: 13px; color: var(--muted); margin-top: 8px; line-height: 1.5; }
.data-card-notes { font-size: 13px; color: var(--ink); margin-top: 8px; font-style: italic; }
.data-card-actions { display: flex; gap: 8px; margin-top: 12px; }
.data-card-actions button {
  flex: 1;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.data-card-actions button.delete { color: var(--danger); border-color: #f0d8d0; }

.tab-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--sand);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 14px;
  font-weight: 700;
  color: var(--teal-dark);
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(80px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
  font-size: 28px;
  border: none;
  box-shadow: 0 8px 18px rgba(217,113,78,0.4);
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Bottom nav ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 8px 4px calc(8px + var(--safe-bottom));
  z-index: 5;
}
.tabbar button {
  flex: 1;
  background: none;
  border: none;
  padding: 6px 2px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.tabbar button .icon { font-size: 20px; }
.tabbar button.active { color: var(--teal); font-weight: 700; }

/* ---------- Modal / bottom sheet form ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20,20,18,0.4);
  z-index: 10;
  display: flex;
  align-items: flex-end;
}
.sheet {
  background: var(--surface);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(24px + var(--safe-bottom));
}
.sheet h2 { margin-bottom: 16px; font-size: 19px; }
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input, .field textarea, .field select {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 16px;
  font-family: inherit;
  background: var(--bg);
}
.field textarea { resize: vertical; min-height: 60px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions button {
  flex: 1;
  padding: 14px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 700;
}
.sheet-actions .cancel { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.sheet-actions .save { background: var(--teal); color: #fff; }

.toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

@media (min-width: 640px) {
  .content { max-width: 560px; margin: 0 auto; width: 100%; }
  .topbar, .tabbar { max-width: 640px; margin: 0 auto; }
  .sheet-backdrop { align-items: center; justify-content: center; }
  .sheet { max-width: 480px; border-radius: 20px; max-height: 85vh; }
}
