:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #1d211f;
  --muted: #6f7772;
  --paper: #f4f4ef;
  --card: rgba(255, 255, 255, 0.92);
  --line: #dfe2dc;
  --gold: #c89a3d;
  --green: #1e8d62;
  --red: #c94c4c;
  --shadow: 0 18px 50px rgba(32, 39, 35, 0.09);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(200, 154, 61, .16), transparent 30rem),
    linear-gradient(145deg, #f8f8f3, #eceee9);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding:
    calc(22px + env(safe-area-inset-top))
    calc(22px + env(safe-area-inset-right))
    calc(22px + env(safe-area-inset-bottom))
    calc(22px + env(safe-area-inset-left));
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; }
.brand h1 { margin: 0; font-size: 1.05rem; letter-spacing: .02em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: .78rem; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.badge { border-radius: 999px; padding: 7px 10px; background: #fff2cc; color: #765714; font-size: .7rem; font-weight: 800; letter-spacing: .06em; }
.privacy { margin: 18px 0; padding: 13px 16px; border: 1px solid #cfe2d8; border-radius: 14px; background: #edf8f2; color: #315b49; font-size: .84rem; line-height: 1.45; }
.tabs { display: inline-flex; padding: 4px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.6); }
.tab { border: 0; border-radius: 9px; padding: 9px 18px; background: transparent; color: var(--muted); font-weight: 700; }
.tab.active { background: var(--ink); color: white; box-shadow: 0 5px 14px rgba(0,0,0,.12); }
.view { display: none; margin-top: 18px; }
.view.active { display: block; }
.card { border: 1px solid rgba(214,218,211,.9); border-radius: 21px; background: var(--card); box-shadow: var(--shadow); padding: 22px; }
.card h2, .card h3 { margin: 0; }
.eyebrow { margin: 0 0 7px; color: var(--gold); font-size: .7rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.subtle { color: var(--muted); font-size: .84rem; }
.agent-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(270px, .65fr); gap: 18px; }
.field { display: grid; gap: 7px; margin-top: 17px; }
.field label { color: #4c534f; font-size: .77rem; font-weight: 800; }
select, textarea, input[type="search"] { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 12px 13px; color: var(--ink); outline: none; }
select:focus, textarea:focus, input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(200,154,61,.13); }
textarea { min-height: 76px; resize: vertical; }
.status-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.status-choice { min-height: 84px; border: 1px solid var(--line); border-radius: 14px; background: #fff; padding: 12px 8px; color: #4f5752; text-align: center; font-size: .78rem; font-weight: 750; }
.status-choice span { display: block; font-size: 1.35rem; margin-bottom: 5px; }
.status-choice.active { border-color: var(--gold); background: #fff9e9; color: #684d12; box-shadow: inset 0 0 0 1px var(--gold); }
.location-panel { margin-top: 17px; padding: 14px; border-radius: 15px; background: #f4f6f3; }
.location-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.location-copy strong { display: block; font-size: .86rem; }
.location-copy small { color: var(--muted); }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: .75rem; font-weight: 750; }
.switch input { width: 18px; height: 18px; accent-color: var(--green); }
.button-row { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 13px; }
.btn { border: 1px solid var(--line); border-radius: 11px; padding: 10px 13px; background: white; color: var(--ink); font-weight: 800; font-size: .78rem; }
.btn:hover { transform: translateY(-1px); }
.btn.primary { border-color: var(--ink); background: var(--ink); color: white; }
.btn.gold { border-color: var(--gold); background: var(--gold); color: #201a0f; }
.btn.danger { border-color: #f0caca; color: var(--red); }
.btn:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.report { width: 100%; margin-top: 17px; padding: 14px; font-size: .9rem; }
.live-strip { display: none; margin-top: 13px; border-radius: 12px; padding: 11px 13px; background: #e8f7ef; color: #246446; font-size: .78rem; font-weight: 750; }
.live-strip.active { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pulse { width: 9px; height: 9px; display: inline-block; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(30,141,98,.4); animation: pulse 1.5s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(30,141,98,0); } }
.recent-status { margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--line); }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 999px; background: #eef1ee; font-size: .72rem; font-weight: 850; }
.side-card { display: flex; flex-direction: column; }
.side-card ol { margin: 16px 0; padding-left: 20px; color: #545c57; font-size: .84rem; line-height: 1.65; }
.install-card { margin-top: auto; border-radius: 15px; padding: 14px; background: #1d211f; color: white; }
.install-card p { margin: 5px 0 0; color: #cbd0cc; font-size: .76rem; line-height: 1.45; }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.summary { padding: 16px; }
.summary strong { display: block; margin-top: 5px; font-size: 1.65rem; }
.admin-grid { display: grid; grid-template-columns: 1.35fr .65fr; gap: 16px; }
.map-card { padding: 9px; overflow: hidden; }
.map-head { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 12px 13px 15px; }
.map-live { color: var(--muted); font-size: .72rem; font-weight: 750; white-space: nowrap; }
.map-wrap { position: relative; }
#map { height: 445px; border: 1px solid #e0e3e0; border-radius: 15px; background: #e6e9e4; font-family: inherit; }
.leaflet-div-icon { background: transparent; border: 0; }
.agent-marker { display: flex; align-items: center; width: max-content; max-width: 166px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.24)); }
.agent-marker-avatar { position: relative; z-index: 2; display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 38px; border: 3px solid #fff; border-radius: 50%; background: #18865d; color: #fff; font-size: .68rem; font-weight: 900; letter-spacing: .03em; }
.agent-marker-name { overflow: hidden; margin-left: -5px; border: 1px solid rgba(0,0,0,.08); border-left: 0; border-radius: 0 8px 8px 0; padding: 6px 9px 6px 11px; background: rgba(255,255,255,.96); color: #303438; font-size: .69rem; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.agent-marker.live .agent-marker-avatar { background: #1a73e8; box-shadow: 0 0 0 5px rgba(26,115,232,.2); animation: markerPulse 1.8s infinite; }
.agent-marker.stale .agent-marker-avatar { background: #8a9290; }
.agent-marker.stale .agent-marker-name { color: #747b79; }
@keyframes markerPulse { 50% { box-shadow: 0 0 0 8px rgba(26,115,232,.05); } }
.leaflet-popup-content-wrapper { border-radius: 14px; box-shadow: 0 8px 28px rgba(0,0,0,.18); }
.leaflet-popup-content { margin: 14px; min-width: 205px; }
.map-popup-title { display: flex; align-items: center; gap: 10px; }
.map-popup-title strong, .map-popup-title small { display: block; }
.map-popup-title small { margin-top: 2px; color: var(--muted); font-size: .7rem; }
.map-popup-avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: #e8f0fe; color: #1967d2; font-size: .68rem; font-weight: 900; }
.map-popup-meta { display: flex; justify-content: space-between; gap: 12px; margin: 12px 0; border-top: 1px solid #ecefec; padding-top: 9px; color: var(--muted); font-size: .65rem; }
.map-popup a { color: #1967d2; font-size: .72rem; font-weight: 800; text-decoration: none; }
.map-legend { position: absolute; z-index: 500; left: 12px; bottom: 12px; display: flex; gap: 11px; border: 1px solid rgba(0,0,0,.08); border-radius: 9px; padding: 7px 9px; background: rgba(255,255,255,.94); box-shadow: 0 2px 8px rgba(0,0,0,.12); color: #525856; font-size: .62rem; font-weight: 750; backdrop-filter: blur(5px); }
.map-legend span { display: flex; align-items: center; gap: 4px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.legend-dot.live { background: #1a73e8; }
.legend-dot.recent { background: #18865d; }
.legend-dot.stale { background: #8a9290; }
.map-empty { position: absolute; z-index: 450; top: 50%; left: 50%; display: none; transform: translate(-50%, -50%); min-width: 190px; border: 1px solid rgba(0,0,0,.08); border-radius: 14px; padding: 16px; background: rgba(255,255,255,.94); box-shadow: 0 6px 22px rgba(0,0,0,.12); text-align: center; }
.map-empty.visible { display: grid; gap: 4px; }
.map-empty > span { color: #1a73e8; font-size: 1.5rem; }
.map-empty small { color: var(--muted); }
.admin-notify { margin-top: 14px; }
.activity-list { display: grid; gap: 11px; max-height: 392px; overflow: auto; margin-top: 15px; }
.activity { border-bottom: 1px solid var(--line); padding-bottom: 10px; font-size: .8rem; }
.activity:last-child { border: 0; }
.activity strong { display: block; margin-bottom: 3px; }
.activity small { color: var(--muted); }
.roster-card { margin-top: 16px; }
.roster-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.roster-head input { width: min(310px, 45vw); }
.roster { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.person { border: 1px solid var(--line); border-radius: 13px; padding: 13px; }
.person-top { display: flex; justify-content: space-between; gap: 8px; }
.person p { margin: 8px 0 0; color: var(--muted); font-size: .74rem; }
.person a { color: #72561b; font-weight: 800; text-decoration: none; }
.toast { position: fixed; z-index: 3000; left: 50%; bottom: 24px; transform: translate(-50%, 20px); min-width: 250px; max-width: calc(100vw - 30px); border-radius: 12px; padding: 12px 15px; background: #1d211f; color: white; opacity: 0; pointer-events: none; transition: .2s ease; box-shadow: var(--shadow); font-size: .82rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #9e3737; }
.hidden { display: none !important; }
.top-actions form { margin: 0; }
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding:
    calc(20px + env(safe-area-inset-top))
    calc(20px + env(safe-area-inset-right))
    calc(20px + env(safe-area-inset-bottom))
    calc(20px + env(safe-area-inset-left));
}
.login-card { width: min(420px, 100%); display: grid; gap: 15px; border: 1px solid var(--line); border-radius: 22px; background: var(--card); box-shadow: var(--shadow); padding: 28px; }
.login-card img { width: 58px; height: 58px; }
.login-card h1, .login-card p { margin: 0; }
.login-card label { display: grid; gap: 7px; color: #4c534f; font-size: .77rem; font-weight: 800; }
.login-card input { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 12px 13px; color: var(--ink); }
.login-card .btn { padding: 13px; }
.login-card > small { color: var(--muted); line-height: 1.4; text-align: center; }
.login-error { border-radius: 11px; padding: 10px 12px; background: #fff0f0; color: #963838; font-size: .8rem; }

@media (max-width: 850px) {
  .agent-layout, .admin-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .roster { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .shell {
    padding:
      calc(14px + env(safe-area-inset-top))
      calc(14px + env(safe-area-inset-right))
      calc(14px + env(safe-area-inset-bottom))
      calc(14px + env(safe-area-inset-left));
  }
  .topbar { display: grid; grid-template-columns: minmax(0, 1fr); align-items: stretch; gap: 12px; }
  .brand { min-width: 0; }
  .brand img { width: 48px; height: 48px; flex: 0 0 48px; }
  .brand h1 { font-size: 1rem; }
  .brand p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .top-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; width: 100%; gap: 8px; }
  .top-actions .badge { display: none; }
  .top-actions .btn { width: 100%; min-height: 44px; padding: 10px 12px; white-space: nowrap; }
  .top-actions form { width: auto; }
  .top-actions form .btn { width: auto; }
  .privacy { margin: 13px 0; }
  .tabs { display: flex; }
  .tab { flex: 1; }
  .card { padding: 17px; border-radius: 17px; }
  .status-grid { grid-template-columns: repeat(2, 1fr); }
  .status-choice { min-height: 76px; }
  .summary-grid { gap: 8px; }
  .summary { padding: 13px; }
  .summary strong { font-size: 1.35rem; }
  .map-head { align-items: flex-start; flex-direction: column; }
  #map { height: 340px; }
  .agent-marker-name { display: none; }
  .map-legend { gap: 7px; }
  .roster { grid-template-columns: 1fr; }
  .roster-head { align-items: stretch; flex-direction: column; }
  .roster-head input { width: 100%; }
}