:root {
  --navy: #0f1b2d;
  --navy-2: #16243a;
  --blue: #0176d3;
  --blue-dark: #014486;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #181818;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #2e844a;
  --red: #ba0517;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
}
#app { min-height: 100%; display: flex; flex-direction: column; }
a { color: var(--blue); text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); border-color: transparent; }
label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin: 10px 0 4px; }

/* ---------- Login ---------- */
.login-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--navy) 0%, var(--blue-dark) 100%); padding: 24px;
}
.login-card {
  background: var(--card); border-radius: 16px; padding: 32px 24px;
  width: 100%; max-width: 360px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-card .logo { font-size: 40px; margin-bottom: 8px; }
.login-card h1 { font-size: 20px; margin-bottom: 2px; }
.login-card p { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-card input { text-align: center; margin-bottom: 12px; }
.err { color: var(--red); font-size: 13px; margin-top: 8px; min-height: 17px; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--navy); color: #fff; padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  display: flex; align-items: center; gap: 10px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-weight: 700; font-size: 17px; flex: 1; }
.topbar .sub { font-size: 11px; opacity: .7; display: block; font-weight: 400; }
.icon-btn { color: #fff; font-size: 20px; padding: 6px; border-radius: 8px; }
.icon-btn:active { background: rgba(255,255,255,.15); }

/* ---------- Content & nav ---------- */
.content { flex: 1; padding: 16px; padding-bottom: calc(76px + var(--safe-bottom)); max-width: 860px; width: 100%; margin: 0 auto; }
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: #fff; border-top: 1px solid var(--border);
  display: flex; padding-bottom: var(--safe-bottom);
}
.bottom-nav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; font-size: 10.5px; font-weight: 600; color: var(--muted);
}
.bottom-nav button .ic { font-size: 21px; }
.bottom-nav button.active { color: var(--blue); }

/* ---------- Cards & stats ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.card h2 { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); border-left: 4px solid var(--blue); cursor: pointer;
}
.stat .num { font-size: 26px; font-weight: 800; line-height: 1.1; }
.stat .lbl { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.bar-row .lbl { width: 150px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar { flex: 1; height: 16px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 6px; }
.bar-row .n { width: 48px; text-align: right; font-weight: 700; font-size: 12.5px; }

/* ---------- Property rows ---------- */
.prop-row {
  background: var(--card); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05); cursor: pointer; border-left: 5px solid transparent;
  position: relative;
}
.prop-row .addr { font-weight: 700; font-size: 14px; }
.prop-row .meta { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.prop-row .outcome-chip {
  display: inline-block; font-size: 10.5px; font-weight: 700; padding: 2px 8px;
  border-radius: 99px; margin-top: 6px; border: 1px solid rgba(0,0,0,.15);
}
.prop-row.done { opacity: .55; }
.prop-row .done-check { position: absolute; top: 10px; right: 12px; color: var(--green); font-size: 16px; font-weight: 800; }
.kind-tag { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; }

/* ---------- Buttons ---------- */
.btn {
  display: block; width: 100%; padding: 13px; border-radius: 10px;
  background: var(--blue); color: #fff; font-weight: 700; font-size: 15px; text-align: center;
}
.btn:active { background: var(--blue-dark); }
.btn.secondary { background: #fff; color: var(--blue); border: 1.5px solid var(--blue); }
.btn.subtle { background: var(--bg); color: var(--text); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- Sheet (modal) ---------- */
.sheet-overlay {
  position: fixed; inset: 0; background: rgba(15,27,45,.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: #fff; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 8px 18px calc(20px + var(--safe-bottom));
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet .grab { width: 40px; height: 4px; background: var(--border); border-radius: 2px; margin: 6px auto 12px; }
.sheet h3 { font-size: 17px; margin-bottom: 2px; }
.sheet .sub { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin: 12px 0; }
.detail-grid div { font-size: 13px; }
.detail-grid .k { color: var(--muted); font-size: 11px; font-weight: 600; }
.notes-box {
  background: var(--bg); border-radius: 8px; padding: 10px 12px; font-size: 12.5px;
  white-space: pre-wrap; max-height: 140px; overflow-y: auto; margin: 8px 0;
}
.call-actions { display: flex; gap: 8px; margin: 10px 0; }
.call-actions a {
  flex: 1; text-align: center; padding: 11px; border-radius: 10px; font-weight: 700; font-size: 14px;
  background: var(--bg);
}
.call-actions a.call { background: var(--green); color: #fff; }

/* ---------- Outcome picker ---------- */
.outcome-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 6px 0; }
.outcome-grid button {
  padding: 10px 4px; border-radius: 9px; font-size: 11.5px; font-weight: 700;
  border: 2px solid var(--border); background: #fff; line-height: 1.25;
}
.outcome-grid button.sel { border-color: var(--navy); box-shadow: 0 0 0 1.5px var(--navy); }

/* ---------- Filters ---------- */
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; margin: 8px 0; }
.chip {
  padding: 7px 13px; border-radius: 99px; background: #fff; border: 1.5px solid var(--border);
  font-size: 12.5px; font-weight: 600;
}
.chip.sel { background: var(--navy); color: #fff; border-color: var(--navy); }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; font-size: 14px; }
.spin { text-align: center; padding: 30px; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 12px; }
.pager button { padding: 8px 18px; background: #fff; border: 1px solid var(--border); border-radius: 8px; font-weight: 700; }
.toast {
  position: fixed; bottom: calc(86px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 11px 20px; border-radius: 99px;
  font-size: 13.5px; font-weight: 600; z-index: 99; box-shadow: 0 6px 20px rgba(0,0,0,.3);
  white-space: nowrap;
}
.section-title { font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 18px 0 8px; }

/* ---------- Desktop layout (≥1000px): sidebar nav, wide content ---------- */
@media (min-width: 1000px) {
  #app:has(> .bottom-nav) {
    display: grid;
    grid-template-columns: 230px 1fr;
    grid-template-rows: auto 1fr;
    height: 100vh;
  }
  .topbar { grid-column: 1 / -1; padding: 16px 24px; }
  .topbar .title { font-size: 19px; }
  .bottom-nav {
    position: static; grid-column: 1; grid-row: 2;
    flex-direction: column; justify-content: flex-start; gap: 2px;
    border-top: none; border-right: 1px solid var(--border);
    padding: 14px 10px; background: #fff; overflow-y: auto;
  }
  .bottom-nav button {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 11px 14px; font-size: 14px; border-radius: 9px; width: 100%;
  }
  .bottom-nav button .ic { font-size: 19px; }
  .bottom-nav button.active { background: #eef5fc; }
  .bottom-nav button:hover:not(.active) { background: var(--bg); }
  .content {
    grid-column: 2; grid-row: 2; overflow-y: auto;
    max-width: none; padding: 24px 32px 32px;
  }
  .content > *, .content .stat-grid { max-width: 1080px; }
  .stat-grid { grid-template-columns: repeat(6, 1fr); }
  .sheet-overlay { align-items: center; }
  .sheet { border-radius: 18px; max-height: 86vh; padding-bottom: 22px; }
  .sheet .grab { display: none; }
  .toast { bottom: 28px; }
  .prop-row:hover { box-shadow: 0 2px 8px rgba(0,0,0,.12); }
  .login-card { padding: 40px 36px; max-width: 400px; }
}
.menu-item {
  display: flex; align-items: center; gap: 12px; background: #fff; padding: 15px 16px;
  border-radius: 10px; margin-bottom: 8px; font-weight: 600; font-size: 14.5px; width: 100%;
  box-shadow: 0 1px 2px rgba(0,0,0,.05); text-align: left; color: var(--text);
}
.menu-item .ic { font-size: 19px; }
