*,
*::before,
*::after { box-sizing: border-box; }

:root {
  --bg: #f3f4f7;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #059669;
  --radius: 16px;
  --nav: 64px;
  --pad: 16px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-bottom: calc(var(--nav) + var(--safe-bottom) + 24px);
}
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  min-height: 100vh;
  background: #fff;
  position: relative;
  padding-bottom: calc(var(--nav) + var(--safe-bottom) + 48px);
  box-shadow: 0 0 0 1px var(--line);
}
.no-nav .app,
body.no-nav .app { padding-bottom: calc(20px + var(--safe-bottom)); }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px var(--pad) 10px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 20;
}
.topbar-left {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  min-width: 0;
  flex: 1;
}
.topbar-right { flex-shrink: 0; padding-top: 2px; }
.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -.03em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.eyebrow {
  font-size: .78rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
}
.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--ink);
  border-radius: 12px;
  flex-shrink: 0;
  margin-left: -6px;
}
.main { padding: 0 var(--pad) 28px; }

.section-title { font-size: 1.05rem; margin: 22px 0 10px; }
.section-kicker {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.pad { padding: 14px; }

.stat-card, .stats-4, .stats-3, .stats-2 { display: grid; gap: 8px; }
.stats-4, .stats-3, .stats-2 { margin-bottom: 12px; }
.stats-4 { grid-template-columns: 1fr 1fr; }
.stats-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats-2 { grid-template-columns: 1fr 1fr; }
.stat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
  min-width: 0;
}
.stat-card b {
  display: block;
  font-size: 1.35rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.stat-card span {
  color: var(--muted);
  font-size: .7rem;
  display: block;
  margin-top: 4px;
  line-height: 1.2;
}

.btn-primary, .btn-ghost, button.btn-primary {
  display: block;
  width: 100%;
  text-align: center;
  border: 0;
  border-radius: 14px;
  padding: 14px 16px;
  min-height: 48px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:active { background: var(--blue-dark); }
.btn-ghost {
  background: #fff;
  color: var(--blue);
  border: 1px solid #dbeafe;
}
.text-link {
  background: none;
  border: 0;
  color: var(--blue);
  font-weight: 700;
  padding: 8px 0;
  cursor: pointer;
  white-space: nowrap;
}
.live-pill {
  background: #ffe4e6;
  color: #be123c;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: .7rem;
  font-weight: 700;
}
.banner {
  display: block;
  border-radius: 14px;
  padding: 12px 14px;
  margin: 10px 0;
  background: #eff6ff;
  color: #1e3a8a;
  line-height: 1.35;
}
.banner.good { background: #ecfdf5; color: #065f46; }
.banner.bad, .banner.warn { background: #fff7ed; color: #9a3412; }
.banner.info { background: #eff6ff; }
.live-banner { background: #ecfdf5; color: #065f46; }
.live-banner small { display: block; font-weight: 500; margin-top: 2px; }

.list { display: flex; flex-direction: column; }
.person-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  color: inherit;
  min-width: 0;
}
.person-row.as-label { cursor: pointer; }
.grow .chip { display: inline-block; margin-top: 6px; }
.grow strong, .person-row strong {
  display: block;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.grow small, .person-row small {
  color: var(--muted);
  font-size: .82rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 2px;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 99px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .78rem;
  background: #dbeafe;
  color: #1d4ed8;
  flex-shrink: 0;
}

.chip {
  font-size: .72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 4px 8px;
  flex-shrink: 0;
  white-space: nowrap;
}
.chip.green { background: #dcfce7; color: #166534; }
.chip.blue { background: #dbeafe; color: #1d4ed8; }
.chip.purple { background: #ede9fe; color: #6d28d9; }
.chip.pink { background: #ffe4e6; color: #be123c; }
.chip.sky { background: #e0f2fe; color: #0369a1; }
.chip.gold { background: #fef3c7; color: #92400e; }
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 0 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip-row.wrap { flex-wrap: wrap; overflow: visible; }
.chip-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 36px;
  white-space: nowrap;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.chip-btn.on, .chip-btn:has(input:checked) {
  background: #eff6ff;
  border-color: #93c5fd;
  color: var(--blue);
  font-weight: 700;
}
.chip-btn input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  min-height: 0;
  pointer-events: none;
}

.sidebar { display: none; }
.workspace { min-width: 0; }

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(480px, 100%);
  background: #fff;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--nav) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  z-index: 30;
}
.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: .65rem;
  color: #9ca3af;
  min-width: 0;
}
.bottom-nav a.active { color: var(--blue); font-weight: 700; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .85rem;
  font-weight: 600;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]),
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  width: 100%;
  min-height: 44px;
  appearance: none;
  -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%236b7280' d='M1 1l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
input[type="date"],
input[type="search"],
input[type="time"] {
  appearance: auto;
  -webkit-appearance: auto;
}
input[type="checkbox"],
input[type="radio"] {
  width: 22px;
  height: 22px;
  min-height: 0;
  min-width: 22px;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--blue);
  border: 0;
  background: none;
  appearance: auto;
  -webkit-appearance: auto;
}

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 10px; }
.outcome-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.outcome {
  border-radius: 16px;
  min-height: 72px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 10px;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid transparent;
  font-size: .92rem;
  line-height: 1.2;
}
.outcome input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  min-height: 0;
  pointer-events: none;
}
.outcome span { pointer-events: none; }
.outcome:has(input:checked) {
  border-color: #111827;
  box-shadow: inset 0 0 0 1px #111827;
}
.oc-green { background: #d1fae5; }
.oc-peach { background: #ffedd5; }
.oc-blue { background: #dbeafe; }
.oc-gold { background: #fde68a; }
.oc-purple { background: #e9d5ff; }
.oc-mauve { background: #e5e7eb; }

.address-line {
  display: flex;
  align-items: center;
  gap: 8px;
}
.address-line .pin { flex-shrink: 0; }
.address-line input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) {
  flex: 1;
  min-width: 0;
  width: auto;
  border: 0;
  padding: 8px 0;
  min-height: 40px;
  border-radius: 0;
}
.address-line .text-link { flex-shrink: 0; }

.row-gap { display: flex; flex-direction: column; gap: 8px; }
.row-between {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}
.row-between > * { min-width: 0; }
.sub-link { display: inline-block; margin: 0 0 10px; font-size: .9rem; }
.task-mini, .task-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: inherit;
  margin-bottom: 8px;
}
.task-mini { flex-direction: row; align-items: flex-start; }
.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: .82rem;
  margin-top: 6px;
}
.meta-row span { min-width: 0; overflow-wrap: anywhere; }
.map {
  height: 220px;
  border-radius: 16px;
  margin: 12px 0;
  border: 1px solid var(--line);
  z-index: 1;
}
.bar { height: 8px; background: #e5e7eb; border-radius: 99px; overflow: hidden; margin: 6px 0 12px; }
.bar > span { display: block; height: 100%; background: var(--blue); }
.bar-row { margin-bottom: 4px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.filters select { min-height: 40px; min-width: 0; }
.toast { margin: 0 16px 8px; padding: 10px 12px; border-radius: 12px; }
.toast-good { background: #ecfdf5; color: #065f46; }
.toast-bad { background: #fef2f2; color: #991b1b; }
.offline-bar {
  position: sticky;
  top: 52px;
  background: #111827;
  color: #fff;
  text-align: center;
  padding: 6px;
  font-size: .8rem;
  z-index: 25;
}

.auth-body {
  min-height: 100dvh;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: var(--bg);
}
.auth-card {
  width: min(400px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 6px; font-size: 1.6rem; }

.mini {
  width: auto;
  min-height: 36px;
  font-size: .78rem;
  padding: 6px 28px 6px 10px;
  background-position: right 8px center;
}
.mini-check, .lead-toggle {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: .8rem;
  white-space: nowrap;
  margin: 0;
}
.lead-toggle {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  min-height: 36px;
  background: #fff;
}
.lead-toggle:has(input:checked) {
  background: #eff6ff;
  border-color: #93c5fd;
  color: var(--blue);
}
.search-bar { margin: 4px 0 10px; }
.search-bar input { margin: 0; }

.vol-card {
  display: grid;
  grid-template-columns: 22px 40px minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  align-items: center;
}
.vol-card > input[type="checkbox"] { grid-column: 1; grid-row: 1; }
.vol-card .avatar { grid-column: 2; grid-row: 1; }
.vol-card .grow { grid-column: 3; grid-row: 1; }
.vol-card .vol-actions {
  grid-column: 3;
  grid-row: 2;
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.vol-card .vol-actions select.mini {
  flex: 1;
  min-width: 0;
  max-width: none;
  width: auto;
}
.seg { display: flex; flex-direction: column; gap: 10px; }

.auth-hero { display: none; }
.dash-actions { display: grid; gap: 10px; margin: 12px 0 8px; }
.dash-grid { display: grid; gap: 16px; }
.page-split { display: grid; gap: 16px; }
.vol-grid { display: grid; gap: 0; }
.task-grid { display: flex; flex-direction: column; }
.export-grid { display: grid; gap: 12px; }
.form-actions { display: flex; flex-direction: column; gap: 10px; }
.home-hero { display: grid; gap: 10px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row .btn-primary, .btn-row .btn-ghost { width: auto; flex: 1; min-width: 140px; }

@media (min-width: 420px) {
  .stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat-card b { font-size: 1.4rem; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 900px) {
  html, body { overflow-x: hidden; background: #eef1f6; }
  html { scroll-padding-bottom: 0; }
  .app {
    max-width: none;
    margin: 0;
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    padding-bottom: 0;
    box-shadow: none;
    background: transparent;
  }
  .sidebar {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 22px 16px 18px;
    background: #0f172a;
    color: #e2e8f0;
    position: sticky;
    top: 0;
    height: 100vh;
  }
  .brand {
    display: flex;
    gap: 12px;
    align-items: center;
    color: #fff;
    padding: 4px 8px 22px;
  }
  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--blue);
    color: #fff;
    font-weight: 800;
    flex-shrink: 0;
  }
  .brand strong { display: block; font-size: 1.05rem; }
  .brand small { color: #94a3b8; font-size: .78rem; }
  .side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
  .side-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #cbd5e1;
    padding: 10px 12px;
    border-radius: 12px;
    font-weight: 600;
  }
  .side-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
  .side-nav a.active { background: #1d4ed8; color: #fff; }
  .sidebar-user {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 10px;
    align-items: center;
    padding: 14px 8px 4px;
    border-top: 1px solid rgba(255,255,255,.08);
    margin-top: 16px;
  }
  .sidebar-user .text-link { color: #93c5fd; width: auto; padding: 0; margin-left: auto; }
  .sidebar-user .avatar { background: #1e3a8a; color: #bfdbfe; }
  .sidebar-user strong { color: #fff; font-size: .9rem; }
  .sidebar-user small { color: #94a3b8; }
  .sidebar-user .text-link { color: #93c5fd; width: 100%; padding: 0; }

  .workspace {
    margin: 16px 16px 16px 0;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 20px;
    min-height: calc(100vh - 32px);
    box-shadow: var(--shadow);
  }
  .bottom-nav { display: none; }
  .topbar {
    padding: 22px 32px 10px;
    border-bottom: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
  }
  .topbar h1 { font-size: 1.7rem; }
  .main { padding: 20px 32px 40px; max-width: 1120px; }
  .mobile-only { display: none !important; }
  .stat-card { padding: 18px 16px; text-align: left; }
  .stat-card b { font-size: 1.8rem; }
  .stat-card span { font-size: .8rem; }
  .home-hero {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    margin: 8px 0 18px;
  }
  .home-hero .banner { margin: 0; }
  .dash-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .dash-grid { grid-template-columns: 1.2fr .8fr; align-items: start; }
  .page-split { grid-template-columns: 1.15fr .85fr; align-items: start; }
  .vol-grid { grid-template-columns: 1fr 1fr; column-gap: 24px; }
  .vol-card {
    grid-template-columns: 22px 40px minmax(0, 1fr) auto;
    align-items: center;
  }
  .vol-card .vol-actions { grid-column: 4; grid-row: 1; }
  .seg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .task-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .export-grid { grid-template-columns: 1fr 1fr; }
  .map { height: 420px; }
  .outcome-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .btn-primary, .btn-ghost, button.btn-primary {
    width: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 180px;
  }
  form.stack > .btn-primary,
  form.stack > .btn-ghost,
  .form-actions .btn-primary,
  .form-actions .btn-ghost {
    width: 100%;
    max-width: 280px;
  }
  .filters { max-width: 520px; }
  .list.card, .card.list { padding: 8px 16px; }
  .narrow-form { max-width: 560px; }
  .auth-body {
    grid-template-columns: 1fr 1fr;
    padding: 0;
    place-items: stretch;
  }
  .auth-hero {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 48px;
    background: #0f172a;
    color: #fff;
  }
  .auth-hero h1 { font-size: 2.4rem; margin: 0 0 12px; }
  .auth-hero p { color: #94a3b8; max-width: 360px; }
  .auth-card {
    width: auto;
    max-width: 440px;
    margin: auto;
    box-shadow: none;
  }
}
