/* ==========================================================================
   Log Visit (modules/features/log-visit.js)
   One phone-first column: company (with location), who was met, related
   deal, type, notes, tags, next step, trip, photo; a sticky Save bar.
   ========================================================================== */

.vl-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 4px 0;
}

/* Fields scrolled into view stop above the sticky Save bar */
html:has(.vl-page) {
  scroll-padding-bottom: 96px;
}

@media (max-width: 768px) {
  html:has(.vl-page) {
    scroll-padding-bottom: calc(var(--bottom-nav-height, 64px) + 88px);
  }
}

.vl-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.vl-head {
  margin-bottom: 4px;
}

.vl-title {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.vl-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.vl-section {
  margin-top: 22px;
}

.vl-label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.vl-optional {
  margin-left: 4px;
  font-weight: 400;
  color: var(--text-muted);
}

.vl-hint {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.vl-count {
  text-align: right;
}

.vl-count:empty {
  display: none;
}

.vl-count.is-limit {
  color: var(--color-danger);
}

/* Until a company is picked the rest is dimmed, but still usable */
.vl-rest {
  transition: opacity 0.2s ease;
}

.vl-rest.is-waiting:not(:focus-within) {
  opacity: 0.55;
}

/* ── Inputs ────────────────────────────────────────────────────────────── */

.vl-input {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.vl-input[hidden] {
  display: none;
}

.vl-input::placeholder {
  color: var(--text-muted);
}

.vl-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-bg);
}

.vl-notes {
  min-height: 132px;
  resize: vertical;
  line-height: 1.5;
}

.vl-notes-wrap {
  position: relative;
}

#vl-contact .vl-input {
  margin-top: 8px;
}

#vl-contact .vl-input:first-child {
  margin-top: 0;
}

.vl-link {
  flex-shrink: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-primary);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.vl-link:hover {
  text-decoration: underline;
}

.vl-link:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ── Company search and the picked company ─────────────────────────────── */

.vl-search {
  position: relative;
}

.vl-search > .vl-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.vl-search .vl-input {
  padding-left: 36px;
}

.vl-results {
  margin-top: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-secondary);
}

.vl-results:empty {
  display: none;
}

.vl-result {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-top: 1px solid var(--border-color-light);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.vl-result:first-child {
  border-top: 0;
}

.vl-result:hover,
.vl-result.is-active {
  background: var(--bg-hover);
}

.vl-result--add .vl-row-name {
  color: var(--color-primary);
  font-weight: 550;
}

.vl-empty {
  padding: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.vl-row-tile {
  display: inline-flex;
  flex-shrink: 0;
}

.vl-add-tile {
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: var(--color-primary-bg);
  color: var(--color-primary);
}

.vl-row-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.vl-row-name {
  overflow: hidden;
  font-size: 14px;
  font-weight: 550;
  color: var(--text-primary);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.vl-row-sub {
  overflow: hidden;
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.vl-row-meta {
  flex-shrink: 0;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.vl-row-meta.is-muted {
  color: var(--text-muted);
}

.vl-selected {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-secondary);
}

/* Where the rep is, relative to the company */
.vl-loc {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--bg-tertiary);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-secondary);
}

.vl-loc > span:not(.btn-spinner) {
  flex: 1;
  min-width: 0;
}

.vl-loc.is-ok {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.vl-loc.is-away,
.vl-loc.is-warn {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.vl-loc.is-ok > span,
.vl-loc.is-away > span,
.vl-loc.is-warn > span {
  color: var(--text-primary);
}

.vl-map {
  height: 200px;
  margin-top: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 10px;
}

.vl-map[hidden] {
  display: none;
}

/* ── Chips: person, deal, type, tags, due ──────────────────────────────── */

.vl-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.vl-chips[hidden] {
  display: none;
}

.vl-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.vl-chip > span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.vl-chip:hover {
  background: var(--bg-hover);
}

.vl-chip[aria-checked="true"],
.vl-chip[aria-pressed="true"] {
  border-color: var(--color-primary);
  background: var(--color-primary-bg);
  color: var(--color-primary);
}

.vl-chip .vl-icon {
  width: 14px;
  height: 14px;
}

.vl-chip--record {
  padding-left: 8px;
}

.vl-chip-meta {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.vl-chip-input {
  width: 116px;
  height: 32px;
  padding: 0 12px;
  border: 1px dashed var(--border-color);
  border-radius: 999px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
}

.vl-chip-input:focus {
  outline: none;
  border-style: solid;
  border-color: var(--color-primary);
}

.vl-chip-date {
  position: relative;
}

/* The real date input covers the chip, so a tap opens the picker anywhere */
.vl-chip-date input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.vl-due {
  margin-top: 8px;
}

/* ── Trip and photo ────────────────────────────────────────────────────── */

.vl-trip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.vl-field-label {
  display: block;
  margin-bottom: 4px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.vl-affix {
  position: relative;
  display: block;
}

.vl-affix .vl-input {
  padding-right: 52px;
}

.vl-affix > span {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
}

.vl-photo-add {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px;
  border: 1px dashed var(--border-color);
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.vl-photo-add:hover {
  background: var(--bg-hover);
}

.vl-photo-add .vl-icon {
  width: 18px;
  height: 18px;
}

.vl-photo-thumb {
  position: relative;
  display: inline-block;
}

.vl-photo-thumb img {
  display: block;
  width: 132px;
  height: 99px;
  object-fit: cover;
  border: 1px solid var(--border-color);
  border-radius: 10px;
}

.vl-photo-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  cursor: pointer;
}

/* ── Banners: waiting visits, restored draft ───────────────────────────── */

.vl-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--color-primary-bg);
  font-size: 13px;
  color: var(--text-secondary);
}

.vl-banner[hidden] {
  display: none;
}

.vl-banner > span {
  flex: 1;
  min-width: 0;
}

.vl-banner .vl-icon {
  color: var(--color-primary);
}

.vl-banner--draft {
  background: var(--bg-tertiary);
}

.vl-banner--draft .vl-icon {
  color: var(--text-muted);
}

/* ── Save bar ──────────────────────────────────────────────────────────── */

/* The page containers hide sideways overflow, which would also make them the
   (non-scrolling) box the sticky bar sticks to. clip trims the same overflow
   without that, so the bar stays on screen while the page scrolls. */
body:has(.vl-page),
#view-container:has(.vl-page),
.main-content:has(.vl-page) {
  overflow-x: clip;
}

.vl-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 28px;
  padding: 12px 0 16px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.vl-bar-status {
  min-width: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.vl-save {
  flex-shrink: 0;
  min-width: 132px;
  height: 40px;
  justify-content: center;
}

@media (max-width: 768px) {
  /* Above the bottom tab bar */
  .vl-bar {
    bottom: calc(var(--bottom-nav-height, 64px) + env(safe-area-inset-bottom, 0px));
  }

  .vl-page {
    padding: 4px 0 0;
  }

  .vl-title {
    font-size: 20px;
  }

  /* 16px stops iOS zooming into a field on focus */
  .vl-input {
    font-size: 16px;
  }

  /* One size for every chip, the tag box included. The app's touch rule
     (buttons at least 40px tall) would otherwise stretch them into ovals. */
  .vl-chip,
  .vl-chip-input {
    height: 36px;
    min-height: 36px;
    padding: 0 14px;
    font-size: 14px;
  }

  .vl-chip--record {
    padding-left: 10px;
  }

  /* 16px text stops iOS zooming in; the placeholder matches the chips */
  .vl-chip-input {
    width: 124px;
    font-size: 16px;
  }

  .vl-chip-input::placeholder {
    font-size: 14px;
  }

  .vl-link,
  .vl-photo-remove {
    min-height: 0;
  }

  .vl-bar {
    margin-left: calc(-1 * var(--mobile-padding, 12px));
    margin-right: calc(-1 * var(--mobile-padding, 12px));
    padding: 10px var(--mobile-padding, 12px);
  }

  .vl-save {
    flex: 1;
    max-width: 220px;
    height: 44px;
  }
}
