/* Rescue HQ — mobile-first styles */
:root {
  /* brand = light blue (the app's main color) */
  --brand: #0ea5e9;
  --brand-dark: #0284c7;
  --brand-light: #e0f2fe;
  /* green stays for "money in / paid / good" meanings only */
  --green: #16a34a;
  --green-dark: #15803d;
  --green-light: #dcfce7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --yellow: #ca8a04;
  --yellow-light: #fef9c3;
  --blue: #2563eb;
  --blue-light: #dbeafe;
  --ink: #1c1917;
  --ink-soft: #78716c;
  --bg: #f5f5f4;
  --card: #ffffff;
  --line: #e7e5e4;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}

.logo-img { height: 24px; width: 24px; border-radius: 6px; align-self: center; }
#topbar {
  background: linear-gradient(120deg, #0ea5e9, #2563eb);
  box-shadow: 0 2px 12px rgba(14, 165, 233, .35);
  color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.logo { font-weight: 800; font-size: 18px; }
#topbar-sub { font-size: 12px; opacity: .85; }

#view { padding: 14px 12px 20px; max-width: 640px; margin: 0 auto; }

h2 { font-size: 17px; margin: 18px 2px 8px; }
h2:first-child { margin-top: 2px; }
.muted { color: var(--ink-soft); font-size: 13px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 2px 10px rgba(28, 25, 23, .06);
}

/* screen transitions — every screen slides in fresh */
@keyframes viewIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(18px) scale(.985); }
  to { opacity: 1; transform: none; }
}
#view.anim > * { animation: cardIn .42s cubic-bezier(.2, .9, .25, 1) both; }
#view.anim > *:nth-child(2) { animation-delay: .04s; }
#view.anim > *:nth-child(3) { animation-delay: .08s; }
#view.anim > *:nth-child(4) { animation-delay: .12s; }
#view.anim > *:nth-child(5) { animation-delay: .16s; }
#view.anim > *:nth-child(6) { animation-delay: .20s; }
#view.anim > *:nth-child(n+7) { animation-delay: .24s; }

@keyframes barGrow { from { height: 0; } }
.bar { animation: barGrow .8s cubic-bezier(.2, .9, .25, 1) both; }
.bar-col:nth-child(2) .bar { animation-delay: .08s; }
.bar-col:nth-child(3) .bar { animation-delay: .16s; }
.bar-col:nth-child(4) .bar { animation-delay: .24s; }
.bar-col:nth-child(5) .bar { animation-delay: .32s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

/* stat grid on Home */
.stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 10px; text-align: center; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.stat .num { font-size: 19px; font-weight: 800; }
.stat .lbl { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }
.pos { color: var(--green-dark); }
.neg { color: var(--red); }

/* lists */
.row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 4px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row { transition: background .15s; border-radius: 8px; }
.row:active { background: var(--brand-light); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; font-size: 15px; }
.row .sub { font-size: 12px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { font-weight: 700; font-size: 15px; white-space: nowrap; }

.chip {
  display: inline-block; font-size: 11px; font-weight: 600;
  border-radius: 999px; padding: 2px 9px;
  background: var(--line); color: var(--ink-soft);
}
.chip.green { background: var(--green-light); color: var(--green-dark); }
.chip.red { background: var(--red-light); color: var(--red); }
.chip.yellow { background: var(--yellow-light); color: var(--yellow); }
.chip.blue { background: var(--blue-light); color: var(--blue); }

/* forms */
label.field { display: block; margin-bottom: 12px; }
label.field .lbl { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  font-size: 16px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
textarea { min-height: 90px; resize: vertical; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 16px; font-weight: 700;
  padding: 13px 18px;
  border: none; border-radius: 12px;
  background: linear-gradient(120deg, #0ea5e9, #2563eb); color: #fff;
  width: 100%; cursor: pointer;
  box-shadow: 0 4px 14px rgba(14, 165, 233, .35);
  transition: transform .12s, box-shadow .12s;
}
.btn:active { transform: scale(.97); box-shadow: 0 2px 6px rgba(14, 165, 233, .3); }
.btn.secondary { background: var(--line); color: var(--ink); box-shadow: none; }
.btn.danger { background: var(--red-light); color: var(--red); box-shadow: none; }
.btn.small { width: auto; padding: 8px 14px; font-size: 13px; }

/* segmented control */
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button {
  flex: 1; border: none; background: transparent;
  padding: 9px 4px; font-size: 14px; font-weight: 600;
  border-radius: 10px; color: var(--ink-soft); cursor: pointer;
}
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* paid toggle */
.toggle2 { display: flex; gap: 8px; }
.toggle2 button {
  flex: 1; padding: 12px; font-size: 15px; font-weight: 700;
  border-radius: 10px; border: 1.5px solid var(--line); background: #fff; color: var(--ink-soft); cursor: pointer;
}
.toggle2 button.on-paid { background: var(--green-light); border-color: var(--green); color: var(--green-dark); }
.toggle2 button.on-unpaid { background: var(--yellow-light); border-color: var(--yellow); color: var(--yellow); }

/* tab bar */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(231, 229, 228, .8);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
#tabbar button { transition: transform .15s; }
#tabbar button.active { transform: translateY(-2px); }
#tabbar button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 8px 0 7px;
  border: none; background: none;
  font-size: 10.5px; font-weight: 600; color: var(--ink-soft);
  cursor: pointer;
}
#tabbar button span { font-size: 21px; }
#tabbar button.active { color: var(--brand-dark); }
#tabbar button.log-btn span {
  background: linear-gradient(120deg, #0ea5e9, #2563eb); color: #fff;
  width: 34px; height: 34px; line-height: 34px;
  border-radius: 50%; font-size: 19px;
  margin-bottom: 1px;
  box-shadow: 0 3px 10px rgba(14, 165, 233, .45);
}

/* search */
.search { margin-bottom: 10px; }

/* client detail */
.linkline { display: flex; gap: 8px; margin: 10px 0; }
.linkline a {
  flex: 1; text-align: center;
  background: var(--blue-light); color: var(--blue);
  font-weight: 700; font-size: 13px;
  padding: 10px; border-radius: 10px; text-decoration: none;
}

/* tables (tax view) */
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
table.simple td:last-child { text-align: right; font-weight: 600; white-space: nowrap; }
table.simple tr.total td { font-weight: 800; border-top: 2px solid var(--ink); border-bottom: none; }

/* toast */
/* reconnecting screen */
#reconnect {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(160deg, #0ea5e9, #1e40af);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; color: #fff; text-align: center; padding: 24px;
  animation: viewIn .4s both;
}
#reconnect h1 { font-size: 22px; }
#reconnect p { opacity: .85; font-size: 14px; line-height: 1.5; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.3); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* PIN lock screen */
#pinScreen {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(160deg, #0ea5e9, #1e40af);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; color: #fff; text-align: center;
  animation: viewIn .4s both;
}
#pinScreen h1 { font-size: 24px; }
#pinScreen p { opacity: .85; font-size: 14px; }
#pinScreen input {
  width: 170px; text-align: center; font-size: 34px; letter-spacing: 14px;
  border: none; border-radius: 14px; padding: 12px 0 12px 14px;
  background: rgba(255, 255, 255, .18); color: #fff; outline: none;
}
#pinErr { font-size: 13px; font-weight: 700; min-height: 18px; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.shake { animation: shake .2s 2; }

#toast {
  position: fixed; left: 50%; bottom: 90px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(28, 25, 23, .92); backdrop-filter: blur(8px); color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: all .25s;
  z-index: 50;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* back button */
.backlink { display: inline-block; margin-bottom: 10px; color: var(--brand-dark); font-weight: 700; font-size: 14px; text-decoration: none; cursor: pointer; }

/* my month card */
.rate-line { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.rate-big {
  font-size: 34px; font-weight: 800; line-height: 1.1;
  background: linear-gradient(120deg, #0ea5e9, #2563eb);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.rate-unit { font-size: 16px; font-weight: 700; color: var(--ink-soft); }
.rate-delta { font-size: 18px; font-weight: 800; text-align: right; }
.fun-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin: 14px 0 6px; text-align: center; }
.fun-grid div { background: var(--bg); border-radius: 10px; padding: 8px 4px; }
.fun-grid b { display: block; font-size: 17px; }
.fun-grid span { font-size: 11px; color: var(--ink-soft); }
.bars { display: flex; align-items: flex-end; justify-content: space-between; gap: 6px; margin-top: 12px; }
.bar-col { flex: 1; text-align: center; }
.bar-val { font-size: 10px; font-weight: 700; color: var(--ink-soft); margin-bottom: 2px; }
.bar { background: var(--brand-light); border-radius: 6px 6px 3px 3px; margin: 0 auto; width: 80%; }
.bar.now { background: var(--brand); }
.bar-lbl { font-size: 11px; font-weight: 600; color: var(--ink-soft); margin-top: 3px; }

/* calendar */
.cal-nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.cal-nav b { font-size: 15px; }
.cal-nav button {
  border: none; background: var(--brand-light); color: var(--brand-dark);
  font-size: 20px; font-weight: 800; width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
}
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 11px; font-weight: 700; color: var(--ink-soft); margin-bottom: 4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-day {
  aspect-ratio: 1; border-radius: 9px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; background: var(--bg); cursor: pointer;
}
.cal-day.pad { background: transparent; cursor: default; }
.cal-day.today { outline: 2px solid var(--brand); }
.cal-day.sel { background: var(--brand); color: #fff; }
.cal-day .dots { font-size: 7px; letter-spacing: 1px; color: var(--brand-dark); height: 8px; line-height: 8px; }
.cal-day.sel .dots { color: #fff; }

details.month { margin-bottom: 8px; }
details.month summary {
  font-weight: 700; font-size: 14px; padding: 10px 4px;
  cursor: pointer; list-style: none;
  display: flex; justify-content: space-between;
}
