:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --line: #d8e0ea;
  --dark: #0f172a;
  --blue: #2563eb;
  --green: #0f9f6e;
  --amber: #b45309;
  --red: #b91c1c;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.12), transparent 38%),
    linear-gradient(315deg, rgba(15, 159, 110, 0.16), transparent 42%),
    #f8fafc;
}

.login-panel {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-lockup,
.nav-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--dark);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 2px;
  font-size: 28px;
}

h2 {
  margin-bottom: 0;
  font-size: 24px;
}

h3 {
  margin-bottom: 10px;
  font-size: 18px;
}

.auth-form,
.panel-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.26);
  outline-offset: 2px;
}

.primary-button,
.accent-button,
.ghost-button,
.export-button,
.control-button,
.nav-button,
.icon-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
}

.primary-button {
  background: var(--blue);
  color: #fff;
  padding: 10px 16px;
}

.danger-button {
  background: #fee2e2;
  border-color: #fecaca;
  color: #991b1b;
  padding: 10px 14px;
}

.accent-button {
  background: var(--green);
  color: #fff;
  padding: 10px 16px;
}

.ghost-button {
  background: #eef2f7;
  color: var(--dark);
  padding: 10px 16px;
}

.export-button {
  background: #eef2ff;
  color: #1d4ed8;
  padding: 8px 12px;
}

.compact {
  min-height: 40px;
  padding: 8px 12px;
}

.message {
  min-height: 22px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.message.error {
  color: var(--red);
}

.setup-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.qr-code {
  width: 184px;
  height: 184px;
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.section-label {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-shell {
  min-height: 100%;
  display: grid;
  grid-template-columns: 248px 1fr;
}

.side-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  background: #101827;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.nav-brand {
  margin-bottom: 18px;
}

.nav-brand .brand-mark {
  background: #fff;
  color: #101827;
}

.nav-brand span {
  display: block;
  color: #a7b3c6;
  font-size: 12px;
  text-transform: capitalize;
}

.nav-button {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  color: #cbd5e1;
  border-color: transparent;
  padding: 10px 12px;
}

.nav-button.active,
.nav-button:hover {
  background: #1e293b;
  color: #fff;
}

.nav-button.subtle {
  margin-top: auto;
  color: #94a3b8;
}

.workspace {
  min-width: 0;
  padding: 18px;
}

.top-bar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.menu-button,
.nav-close {
  display: none;
}

.menu-button {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.menu-button span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--dark);
}

.nav-scrim {
  position: fixed;
  inset: 0;
  z-index: 38;
  background: rgba(15, 23, 42, 0.38);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.status-pill.good {
  border-color: rgba(15, 159, 110, 0.28);
  color: var(--green);
}

.status-pill.warn {
  border-color: rgba(180, 83, 9, 0.28);
  color: var(--amber);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.field-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  height: calc(100vh - 106px);
  min-height: 620px;
}

.map-surface {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e5edf5;
}

#map {
  position: absolute;
  inset: 0;
}

.map-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  background: #eef2f7;
  color: var(--muted);
}

.map-controls,
.map-secondary-controls,
.drive-controls,
.tag-controls {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.map-controls {
  top: 14px;
  right: 14px;
}

.map-secondary-controls {
  top: 62px;
  right: 14px;
}

.drive-controls {
  left: 14px;
  bottom: 14px;
}

.tag-controls {
  right: 14px;
  bottom: 14px;
}

.control-button {
  background: rgba(255, 255, 255, 0.94);
  border-color: var(--line);
  color: var(--dark);
  padding: 8px 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.1);
}

.control-button-square {
  width: 38px;
  padding-inline: 0;
}

.control-button.active {
  color: #fff;
  background: var(--dark);
}

.user-location-beacon {
  position: absolute;
  width: 48px;
  height: 48px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 20;
}

.beacon-dot,
.beacon-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 999px;
  transform: translate(-50%, -50%);
}

.beacon-dot {
  width: 18px;
  height: 18px;
  background: #2563eb;
  border: 4px solid #fff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.45), 0 10px 24px rgba(15, 23, 42, 0.3);
  animation: beaconBlink 3.8s ease-in-out infinite;
}

.beacon-ring {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(37, 99, 235, 0.42);
  animation: beaconPulse 4.6s ease-out infinite;
}

.beacon-ring-two {
  animation-delay: 2.2s;
}

@keyframes beaconPulse {
  0% {
    opacity: 0.34;
    width: 18px;
    height: 18px;
  }
  78% {
    opacity: 0;
    width: 42px;
    height: 42px;
  }
  100% {
    opacity: 0;
    width: 42px;
    height: 42px;
  }
}

@keyframes beaconBlink {
  0%,
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    opacity: 0.88;
    transform: translate(-50%, -50%) scale(0.96);
  }
}

@media (prefers-reduced-motion: reduce) {
  .beacon-dot,
  .beacon-ring {
    animation: none;
  }
}

.tag-sheet {
  position: absolute;
  z-index: 3;
  left: 14px;
  right: 14px;
  bottom: 70px;
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sheet-header h3 {
  margin: 0;
  overflow-wrap: anywhere;
}

.existing-lead-notice {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(249, 115, 22, 0.34);
  border-radius: 8px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 13px;
  font-weight: 800;
}

.map-info-window {
  display: grid;
  gap: 3px;
  max-width: 230px;
  color: #111827;
  font: 13px/1.35 Inter, ui-sans-serif, system-ui, sans-serif;
}

.map-info-window strong {
  overflow-wrap: anywhere;
}

.map-info-window span {
  color: #ea580c;
  font-weight: 900;
}

.map-info-window small {
  color: #475569;
}

.map-info-button {
  width: 100%;
  min-height: 34px;
  margin-top: 4px;
  border: 0;
  border-radius: 8px;
  background: #2563eb;
  color: #ffffff;
  font: 800 12px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
}

.icon-button {
  width: 44px;
  padding: 0;
  background: #eef2f7;
  color: var(--dark);
}

.rating-row,
.tag-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rating-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--dark);
  font-weight: 900;
  cursor: pointer;
}

.rating-button.active {
  background: var(--amber);
  color: #fff;
}

.tag-options label {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--dark);
}

.tag-options input {
  min-height: auto;
}

.lead-rail,
.panel-form,
.user-list,
.lead-table,
.lead-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.lead-rail {
  min-width: 0;
  overflow: auto;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border-bottom: 1px solid var(--line);
}

.metric-row div {
  padding: 16px;
}

.metric-row div + div {
  border-left: 1px solid var(--line);
}

.metric-row span {
  display: block;
  font-size: 30px;
  font-weight: 900;
}

.metric-row small {
  color: var(--muted);
  font-weight: 800;
}

.lead-list {
  display: grid;
}

.lead-item {
  display: grid;
  gap: 6px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.lead-item strong {
  overflow-wrap: anywhere;
}

.lead-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2f7;
}

.list-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.list-toolbar input {
  flex: 1;
}

.lead-table {
  overflow: hidden;
}

.lead-editor {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  padding: 16px;
}

.editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.editor-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.lead-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 120px 150px 210px;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.lead-row.header {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: #f8fafc;
}

.team-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
}

.panel-form {
  padding: 16px;
  align-self: start;
}

.user-list {
  overflow: hidden;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 130px 120px 140px;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: fixed;
    z-index: 40;
    left: 0;
    right: auto;
    bottom: auto;
    top: 0;
    width: min(82vw, 310px);
    height: 100dvh;
    padding: 18px;
    transform: translateX(-104%);
    transition: transform 180ms ease;
    box-shadow: 18px 0 44px rgba(15, 23, 42, 0.24);
  }

  .app-shell.menu-open .side-nav {
    transform: translateX(0);
  }

  .nav-button {
    min-height: 44px;
    justify-content: flex-start;
  }

  .nav-button.subtle {
    margin-top: auto;
  }

  .nav-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 1px solid rgba(203, 213, 225, 0.22);
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    border-radius: 8px;
    font-weight: 900;
  }

  .menu-button {
    display: grid;
    align-content: center;
    gap: 4px;
  }

  .workspace {
    padding: 12px;
  }

  .top-bar {
    align-items: flex-start;
    min-height: 76px;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .app-shell.field-mode {
    min-height: 100dvh;
    overflow: hidden;
  }

  .app-shell.field-mode .workspace {
    height: 100dvh;
    padding: 0;
    overflow: hidden;
  }

  .app-shell.field-mode .top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 6;
    min-height: 58px;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    align-items: center;
    padding: calc(env(safe-area-inset-top) + 7px) 10px 7px;
    border-bottom: 1px solid rgba(216, 224, 234, 0.78);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.1);
    backdrop-filter: blur(14px);
  }

  .app-shell.field-mode .top-bar .section-label,
  .app-shell.field-mode .export-button {
    display: none;
  }

  .app-shell.field-mode .top-bar h2 {
    margin: 0;
    font-size: 16px;
    line-height: 1.1;
  }

  .app-shell.field-mode .top-actions {
    grid-column: auto;
    justify-content: flex-end;
  }

  .app-shell.field-mode .status-pill {
    max-width: 132px;
    min-height: 34px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 12px;
  }

  .field-layout {
    display: block;
    height: calc(100dvh - 112px);
    min-height: 500px;
  }

  .app-shell.field-mode .field-layout {
    height: 100dvh;
    min-height: 0;
  }

  .map-surface {
    height: 100%;
  }

  .app-shell.field-mode .map-surface {
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .lead-rail {
    display: none;
  }

  .tag-sheet {
    left: 8px;
    right: 8px;
    bottom: 70px;
    max-height: 68vh;
    overflow: auto;
  }

  .app-shell.field-mode .tag-sheet {
    bottom: calc(env(safe-area-inset-bottom) + 76px);
    max-height: 62vh;
  }

  .map-controls {
    top: 10px;
    right: 10px;
    max-width: min(286px, calc(100vw - 20px));
    justify-content: flex-end;
  }

  .app-shell.field-mode .map-controls {
    top: calc(env(safe-area-inset-top) + 68px);
    left: 10px;
    right: 10px;
    display: grid;
    grid-template-columns: 1.25fr 46px 46px 1fr 1fr;
    max-width: none;
    gap: 7px;
  }

  .map-secondary-controls {
    top: 58px;
    right: 10px;
  }

  .app-shell.field-mode .map-secondary-controls {
    top: calc(env(safe-area-inset-top) + 119px);
    right: 10px;
    display: grid;
    grid-template-columns: repeat(2, minmax(84px, 1fr));
    max-width: 190px;
    gap: 7px;
  }

  .app-shell.field-mode .control-button {
    min-height: 44px;
    padding: 8px;
    border: 1px solid rgba(148, 163, 184, 0.38);
    background: rgba(255, 255, 255, 0.96);
    font-size: 13px;
    font-weight: 900;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
    backdrop-filter: blur(12px);
  }

  .app-shell.field-mode .control-button-square {
    width: auto;
    font-size: 18px;
    line-height: 1;
  }

  .drive-controls {
    left: 10px;
    bottom: 10px;
  }

  .app-shell.field-mode .drive-controls {
    top: calc(env(safe-area-inset-top) + 119px);
    left: 10px;
    right: auto;
    bottom: auto;
    width: min(168px, calc(100vw - 224px));
  }

  .app-shell.field-mode .drive-controls .primary-button {
    width: 100%;
    min-height: 44px;
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.28);
  }

  .app-shell.field-mode .drive-controls .primary-button.active {
    background: #b91c1c;
    box-shadow: 0 12px 28px rgba(185, 28, 28, 0.26);
  }

  .tag-controls {
    right: 10px;
    bottom: 10px;
  }

  .app-shell.field-mode .tag-controls {
    left: 10px;
    right: 10px;
    bottom: calc(env(safe-area-inset-bottom) + 12px);
  }

  .app-shell.field-mode .tag-controls .accent-button {
    width: 100%;
    min-height: 54px;
    border-radius: 8px;
    font-size: 16px;
    box-shadow: 0 16px 34px rgba(15, 159, 110, 0.32);
  }

  .team-grid {
    grid-template-columns: 1fr;
  }

  .lead-row,
  .user-row {
    grid-template-columns: 1fr;
  }

  .editor-grid {
    grid-template-columns: 1fr;
  }

  .lead-row.header {
    display: none;
  }
}

@media (max-width: 560px) {
  .login-panel {
    padding: 20px;
  }

  .top-bar {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: center;
  }

  .top-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .list-toolbar {
    display: grid;
  }

  .map-controls {
    left: 10px;
    right: 10px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    justify-content: stretch;
  }

  .map-controls .control-button {
    min-height: 38px;
    padding-inline: 6px;
    font-size: 12px;
  }

  .control-button-square {
    width: auto;
  }

  .drive-controls {
    right: 10px;
  }
}

@media (max-width: 420px) {
  .app-shell.field-mode .top-bar {
    grid-template-columns: 44px minmax(0, 1fr) auto;
  }

  .app-shell.field-mode .status-pill {
    max-width: 108px;
  }

  .app-shell.field-mode .map-controls {
    grid-template-columns: 1.25fr 44px 44px 0.95fr 0.95fr;
    gap: 6px;
  }

  .app-shell.field-mode .map-secondary-controls {
    top: calc(env(safe-area-inset-top) + 119px);
    left: 10px;
    right: 10px;
    max-width: none;
    grid-template-columns: 1fr 1fr;
  }

  .app-shell.field-mode .drive-controls {
    top: calc(env(safe-area-inset-top) + 170px);
    left: 10px;
    right: 10px;
    width: auto;
  }

  .app-shell.field-mode .tag-sheet {
    bottom: calc(env(safe-area-inset-bottom) + 76px);
    max-height: 55vh;
  }
}
