/* CashSync — dark navy, iOS-native feel. System fonts, safe-area aware. */

:root {
  --bg: #f4eff1;
  --bg-deep: #e9e1e6;
  --card: #ffffff;
  --card-soft: #f9f3f6;
  --line: rgba(90, 40, 65, 0.12);
  --ink: #352730;
  --muted: #8a7581;
  --accent: #b8356f;
  --accent-ink: #ffffff;
  --accent-pastel: #f9dae8;
  --warn: #9a6b12;
  --danger: #c0453e;
  --danger-pastel: #fdeceb;
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: only light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

/* ---- Top nav bar (iOS large-title style) ---- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(244, 239, 241, 0.88);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.navbar-inner {
  padding: 12px 20px 10px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 9px; }

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.brand-name { font-size: 21px; font-weight: 700; letter-spacing: -0.3px; }
.navbar-sub { margin: 0; font-size: 13px; color: var(--muted); }

/* ---- Content ---- */
.content { padding: 16px 16px 0; }
.view[hidden] { display: none; }

.page-title { font-size: 30px; font-weight: 800; letter-spacing: -0.5px; margin: 4px 4px 2px; }
.page-sub { margin: 0 4px 14px; color: var(--muted); font-size: 14px; line-height: 1.45; }

/* ---- Week navigator ---- */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.week-nav-mid { text-align: center; }
.week-range { margin: 0; font-size: 15px; font-weight: 700; }
.today-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
  min-height: 32px;
}

.nav-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.nav-btn:active { background: var(--card-soft); }

/* ---- Summary card ---- */
.summary-card {
  background: linear-gradient(165deg, var(--accent-pastel) 0%, var(--card) 70%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.summary-top { display: flex; justify-content: space-between; gap: 12px; }
.summary-label { margin: 0; font-size: 13px; color: var(--muted); }
.summary-total {
  margin: 2px 0 0;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}

.summary-side { display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.summary-row {
  margin: 0;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.summary-row strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.progress {
  height: 8px;
  border-radius: 99px;
  background: rgba(184, 53, 111, 0.15);
  margin-top: 14px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.35s ease;
}
.summary-note { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

/* ---- Day groups ---- */
.day-group { margin-bottom: 14px; }
.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 6px 8px;
}
.day-name { margin: 0; font-size: 15px; font-weight: 700; }
.day-name .day-date { color: var(--muted); font-weight: 500; }
.day-sum { margin: 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.bill-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.bill-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  min-height: 60px;
}
.bill-row:last-child { border-bottom: none; }

.check {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
}
.bill-row.paid .check {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.bill-info { flex: 1; min-width: 0; }
.bill-name { display: block; font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bill-row.paid .bill-name { color: var(--muted); text-decoration: line-through; }
.bill-cat { display: block; font-size: 13px; color: var(--muted); margin-top: 1px; }

.bill-amount { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bill-row.paid .bill-amount { color: var(--muted); font-weight: 500; }

.empty {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

/* ---- Cards (manage view) ---- */
.card, .summary-card, .bill-list, .empty {
  box-shadow: 0 1px 2px rgba(53, 39, 48, 0.05), 0 4px 14px rgba(53, 39, 48, 0.06);
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title { margin: 0 0 12px; font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-text { margin: 0 0 12px; font-size: 14px; line-height: 1.5; color: var(--muted); }
.card-text code { color: var(--ink); font-size: 12.5px; }

.count-pill {
  font-size: 13px;
  font-weight: 700;
  background: var(--card-soft);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 1px 10px;
  color: var(--muted);
}

/* ---- Forms ---- */
.field { display: block; margin-bottom: 12px; }
.card .field:last-child { margin-bottom: 0; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"], input[type="number"], select {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  padding: 12px;
  min-height: 48px;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-error { color: var(--danger); font-size: 13px; margin: 0 0 10px; }

.btn-primary, .btn-secondary, .btn-ghost, .btn-danger {
  font: inherit;
  font-weight: 700;
  border-radius: 12px;
  min-height: 48px;
  padding: 12px 18px;
  cursor: pointer;
  touch-action: manipulation;
  border: 1px solid transparent;
}
.btn-primary { width: 100%; background: var(--accent); color: var(--accent-ink); font-size: 16px; }
.btn-primary:active { filter: brightness(0.92); }
.btn-secondary { background: var(--card-soft); color: var(--ink); border-color: var(--line); display: inline-block; }
.btn-ghost { background: none; color: var(--accent); }
.btn-danger { width: 100%; background: var(--danger-pastel); color: var(--danger); border-color: rgba(192, 69, 62, 0.35); }
.btn-danger.armed { background: var(--danger); color: #ffffff; }

.import-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.import-msg { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.import-msg.ok { color: var(--accent); }
.import-msg.err { color: var(--danger); }

/* ---- All-bills rows ---- */
.manage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.manage-row:last-child { border-bottom: none; }
.day-badge {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-pastel);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}
.day-badge b { font-size: 16px; }
.day-badge small { font-size: 9px; color: var(--muted); text-transform: uppercase; }
.manage-info { flex: 1; min-width: 0; }
.manage-info .bill-name { font-size: 15px; }
.manage-amount { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; }

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 17px;
  touch-action: manipulation;
}
.icon-btn:active { background: var(--card-soft); color: var(--danger); }

.privacy-note { text-align: center; color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 18px 8px 8px; }

/* ---- iOS tab bar ---- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  backdrop-filter: blur(18px) saturate(1.5);
  border-top: 1px solid var(--line);
  z-index: 20;
}

.tab {
  flex: 1;
  border: none;
  background: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.tab.active { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .progress-fill { transition: none; }
}
