/* ============================================================
   Agent Locator — Custom Styles
   Design tokens mirrored from the original React/Tailwind app
   ============================================================ */

:root {
  --primary:            hsl(210, 80%, 35%);
  --primary-foreground: hsl(0, 0%, 100%);
  --secondary:          hsl(210, 40%, 96.1%);
  --secondary-foreground: hsl(222.2, 47.4%, 11.2%);
  --background:         hsl(0, 0%, 100%);
  --foreground:         hsl(222.2, 84%, 4.9%);
  --card:               hsl(0, 0%, 100%);
  --muted:              hsl(210, 40%, 96.1%);
  --muted-foreground:   hsl(215.4, 16.3%, 46.9%);
  --accent:             hsl(210, 40%, 96.1%);
  --border:             hsl(214.3, 31.8%, 91.4%);
  --sidebar-bg:         hsl(0, 0%, 98%);
  --sidebar-foreground: hsl(240, 5.3%, 26.1%);
  --radius:             0.5rem;
}

/* ── Reset / Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
               Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  background: var(--background);
  color: var(--foreground);
  font-size: 14px;
}

/* ── App Shell ──────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────── */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--primary);
  color: var(--primary-foreground);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  z-index: 1000;
  flex-shrink: 0;
}

#header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

#header-left h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1;
}

#agent-count {
  font-size: 0.8rem;
  opacity: 0.8;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Header buttons */
.btn-header {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
  background: var(--secondary);
  color: var(--secondary-foreground);
}

.btn-header:hover:not(:disabled) {
  background: hsl(210, 40%, 90%);
}

.btn-header:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-header i { font-size: 0.85rem; }

/* Hide button text on small screens */
@media (max-width: 575px) {
  .btn-label { display: none; }
  #agent-count { display: none; }
  .btn-header { padding: 5px 8px; }
}

/* ── Main content area ──────────────────────────────────── */
#main-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

@media (min-width: 768px) {
  #main-content { flex-direction: row; }
}

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar-wrapper {
  width: 100%;
  height: 300px;
  flex-shrink: 0;
  overflow: hidden;
}

@media (min-width: 768px) {
  #sidebar-wrapper {
    width: 30%;
    min-width: 280px;
    max-width: 400px;
    height: auto;
  }
}

#sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

#sidebar-header {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
  flex-shrink: 0;
}

#sidebar-count {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--sidebar-foreground);
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 10px;
}

.search-wrapper {
  position: relative;
  margin-bottom: 8px;
}

.search-wrapper i {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted-foreground);
  font-size: 0.8rem;
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 7px 10px 7px 30px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--background);
  color: var(--foreground);
  outline: none;
  transition: box-shadow 0.15s;
}

#search-input::placeholder { color: var(--muted-foreground); }

#search-input:focus {
  box-shadow: 0 0 0 2px rgba(43, 90, 127, 0.25);
  border-color: var(--primary);
}

#region-filter {
  width: 100%;
  padding: 7px 10px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--background);
  color: var(--foreground);
  outline: none;
  transition: box-shadow 0.15s;
  appearance: auto;
}

#region-filter:focus {
  box-shadow: 0 0 0 2px rgba(43, 90, 127, 0.25);
  border-color: var(--primary);
}

/* ── Agent list (virtual scroll) ───────────────────────── */
#agent-list-scroll {
  flex: 1;
  overflow-y: auto;
}

#agent-list-inner {
  position: relative;
}

.agent-item {
  position: absolute;
  left: 0;
  right: 0;
  height: 64px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: transparent;
  text-align: left;
  width: 100%;
  border-left: none;
  border-right: none;
  border-top: none;
}

.agent-item:hover { background: var(--accent); }
.agent-item.selected { background: var(--accent); }

.agent-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.agent-location {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--muted-foreground);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-location i { font-size: 0.65rem; flex-shrink: 0; }

#no-agents-msg {
  padding: 24px;
  text-align: center;
  color: var(--muted-foreground);
  font-size: 0.8rem;
}

/* ── Map panel ───────────────────────────────────────────── */
#map-wrapper {
  flex: 1;
  min-height: 400px;
  padding: 8px;
  /* Make a flex column so #map can use flex:1 reliably */
  display: flex;
  flex-direction: column;
}

@media (min-width: 768px) {
  #map-wrapper { min-height: 0; }
}

#map {
  flex: 1;           /* fills all space left by padding */
  min-height: 0;     /* allow shrinking below content size */
  width: 100%;
  border-radius: var(--radius);
}

/* ── Leaflet overrides ───────────────────────────────────── */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.leaflet-popup-content {
  margin: 10px 14px;
  font-size: 0.8rem;
  line-height: 1.5;
}

.leaflet-popup-content strong {
  display: block;
  margin-bottom: 2px;
  font-size: 0.85rem;
}

/* hide routing machine panel */
.leaflet-routing-container {
  display: none !important;
}

/* ── Toasts ──────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.app-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  min-width: 240px;
  max-width: 340px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  font-size: 0.82rem;
  line-height: 1.4;
  pointer-events: all;
  animation: toastIn 0.25s ease;
  background: #fff;
  border-left: 4px solid var(--primary);
  color: var(--foreground);
}

.app-toast.toast-success { border-left-color: #22c55e; }
.app-toast.toast-error   { border-left-color: #ef4444; }

.app-toast i { margin-top: 1px; font-size: 0.9rem; }
.app-toast.toast-success i { color: #22c55e; }
.app-toast.toast-error   i { color: #ef4444; }
.app-toast .toast-body { flex: 1; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(30px); }
}

/* ── Custom cluster icon ─────────────────────────────────── */
.custom-cluster-icon {
  background: transparent !important;
  border: none !important;
}

/* ── Popup "Directions" button ───────────────────────────── */
.popup-dir-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  padding: 5px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  width: 100%;
  justify-content: center;
  letter-spacing: 0.01em;
}

.popup-dir-btn:hover {
  background: hsl(210, 80%, 28%);
}

.popup-dir-btn i {
  font-size: 0.8rem;
}
