:root {
  --green: #2e7d32;
  --green-dark: #1b3a1e;
  --ink: #24292e;
  --muted: #6a737d;
  --border: #d9dee2;
  --bg: #f7f8f6;
  --danger: #c62828;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--green-dark);
  color: white;
}

.topbar-title { font-weight: 600; font-size: 18px; }

.topbar-nav { display: flex; gap: 16px; align-items: center; }
.topbar-nav a { color: white; text-decoration: none; opacity: 0.9; }
.topbar-nav a:hover { opacity: 1; text-decoration: underline; }
.topbar-nav select { padding: 4px 8px; border-radius: 6px; border: none; }

main { padding: 20px; max-width: 1100px; margin: 0 auto; }

.map-only { max-width: none; padding: 0; position: relative; }
.map.full { width: 100%; height: calc(100vh - 52px); }

.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 16px;
}

.hidden { display: none !important; }

.field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-family: inherit; }
.field textarea { resize: vertical; }
.field.wide { flex: 2; }

.row { display: flex; gap: 12px; align-items: flex-end; }
.row3 { display: flex; gap: 12px; }
.row3 > .field { flex: 1; }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 8px 0; }

button {
  background: var(--green);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
}
button:hover { background: var(--green-dark); }
button.secondary { background: #6a737d; }
button.danger { background: var(--danger); }

.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }

.item-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  gap: 10px;
}
.row-actions { display: flex; gap: 6px; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; margin-left: 6px; }
.badge.ok { background: #e3f2ec; color: var(--green-dark); }
.badge.warn { background: #fdecea; color: var(--danger); }

.existing-list { margin-top: 16px; }

.workspace-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.workspace-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }

.map-panel { position: sticky; top: 20px; }
.map { width: 100%; height: 480px; border-radius: 10px; border: 1px solid var(--border); }
.map-controls { display: flex; align-items: center; gap: 12px; margin-top: 10px; }

.side-panel { display: flex; flex-direction: column; }

.join-layout { max-width: 560px; }
.profile-layout { max-width: 720px; }

.link-btn { background: none; border: none; color: var(--green-dark); text-decoration: underline; padding: 0; cursor: pointer; font-size: 13px; }

.add-form { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }

.family-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mini-thumb { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.call-btn {
  background: var(--green);
  color: white;
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
}
.call-btn:hover { background: var(--green-dark); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-top: 10px; }
.photo-card { border: 1px solid var(--border); border-radius: 8px; padding: 8px; text-align: center; position: relative; }
.photo-card img { width: 100%; height: 110px; object-fit: cover; border-radius: 6px; }
.photo-caption { font-size: 12px; margin-top: 6px; }
.photo-card button { margin-top: 6px; width: 100%; }

input[type="color"] { width: 40px; height: 32px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; }

.hold-tooltip { font-size: 13px; font-weight: 600; color: var(--ink); padding: 2px 4px; white-space: nowrap; }
.hold-tooltip-leaflet { font-size: 13px; font-weight: 600; color: var(--ink); }

.phone-link { color: var(--green-dark); text-decoration: underline; cursor: pointer; background: none; border: none; padding: 0; font: inherit; }
.phone-link:hover { color: var(--green); }

/* --- Satellite lot tracer (admin) -------------------------------------- */
.leaflet-container { border-radius: 10px; border: 1px solid var(--border); }

/* --- Messages ----------------------------------------------------------- */
.messages-layout { max-width: 1100px; }
.messages-grid { display: grid; grid-template-columns: 340px 1fr; gap: 18px; align-items: start; }
.thread-panel { min-height: 480px; display: flex; flex-direction: column; }

.conversation-item { cursor: pointer; align-items: flex-start; }
.conversation-item.selected { background: #eef4ee; border-color: var(--green); }

.thread-messages {
  flex: 1;
  overflow-y: auto;
  max-height: 55vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 0;
}
.message-bubble {
  align-self: flex-start;
  max-width: 80%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
}
.message-bubble.mine { align-self: flex-end; background: #e3f2ec; border-color: var(--green); }
.message-meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }

@media (max-width: 860px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .map-panel { position: static; }
  .messages-grid { grid-template-columns: 1fr; }
}
