/* ═══════════════════════════════════════════════════════════════════════════
   Design tokens
   ═══════════════════════════════════════════════════════════════════════════ */
:root {
  --color-primary:        #2563eb;
  --color-primary-dark:   #1d4ed8;
  --color-bg-sidebar:     #f8fafc;
  --color-border:         #e2e8f0;
  --color-text:           #1e293b;
  --color-text-muted:     #64748b;
  --color-hover:          #f1f5f9;
  --color-active:         #dbeafe;

  /* Per-section badge colours */
  --color-tag:      #2563eb;
  --color-location: #d97706;
  --color-line:     #16a34a;
  --color-nearby:   #7c3aed;

  --sidebar-width:  320px;
  --header-height:  60px;
  --footer-height:  40px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Map
   ═══════════════════════════════════════════════════════════════════════════ */
#map {
  width: 100%;
  height: 100%;
}

.line-popup {
  min-width: 220px;
  max-width: 420px;
  font-family: sans-serif;
}

.line-popup__title {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  color: var(--color-text);
}

.line-popup__meta {
  margin: 0 0 0.75rem;
  color: var(--color-text-muted);
}

.line-popup__section {
  margin-top: 0.5rem;
}

.line-popup__section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.line-popup .metadata-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  margin: 0;
  font-size: 0.88em;
}

.line-popup .metadata-list--nested {
  margin: 0.25rem 0 0 0.5rem;
  padding-left: 0.5rem;
  border-left: 2px solid var(--color-border);
}

.line-popup .metadata-key {
  font-weight: 600;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.line-popup .metadata-value {
  margin: 0;
  color: var(--color-text);
  word-break: break-word;
}

.line-popup .metadata-value details {
  cursor: pointer;
}

.line-popup .metadata-value summary {
  cursor: pointer;
  color: var(--color-primary);
  list-style: none;
  font-size: 0.85em;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Search bar
   ═══════════════════════════════════════════════════════════════════════════ */
.search-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--color-border);
  background: #fff;
}

.search-input {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.9em;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  outline: none;
  color: var(--color-text);
  transition: border-color 0.15s, box-shadow 0.15s;
  /* override global style.css input styles */
  width: auto;
  margin-top: 0;
}

.search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.search-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1em;
  color: var(--color-text-muted);
  transition: background 0.15s, border-color 0.15s;
  /* override global button styles */
  width: auto;
  min-width: auto;
  min-height: auto;
  margin-top: 0;
}

.search-btn:hover {
  background: var(--color-hover);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Search result sections
   ═══════════════════════════════════════════════════════════════════════════ */
.search-section {
  border-bottom: 1px solid var(--color-border);
}

.search-section:last-child {
  border-bottom: none;
}

.search-section-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--color-bg-sidebar);
  border: 0;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  color: var(--color-text);
  text-align: left;
  font: inherit;
}

.search-section-header:hover {
  background: #eef4ff;
}

.search-section-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.search-section-badge {
  font-size: 0.7em;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 20px;
  color: #fff;
  background: var(--color-text-muted);
}

.search-section-count {
  font-size: 0.75em;
  color: var(--color-text-muted);
  font-weight: 500;
}

.search-section-toggle {
  display: inline-block;
  font-size: 0.9em;
  line-height: 1;
  color: var(--color-text-muted);
  transition: transform 0.15s ease;
}

.search-section-header[aria-expanded='false'] .search-section-toggle {
  transform: rotate(-90deg);
}

.search-section-body[hidden] {
  display: none;
}

.search-section-header--tag     .search-section-badge { background: var(--color-tag); }
.search-section-header--location .search-section-badge { background: var(--color-location); }
.search-section-header--line    .search-section-badge { background: var(--color-line); }
.search-section-header--nearby  .search-section-badge { background: var(--color-nearby); }

.search-empty {
  padding: 12px 10px;
  font-size: 0.9em;
  color: var(--color-text-muted);
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Tag & result items
   ═══════════════════════════════════════════════════════════════════════════ */
.tag-item {
  padding: 8px 10px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875em;
  color: var(--color-text);
  min-height: 44px;
  transition: background 0.1s;
}

.tag-item:hover {
  background: var(--color-hover);
}

.tag-item:last-child {
  border-bottom: none;
}

.tag-item.resolved {
  opacity: 0.6;
}

.tag-item.resolved:hover {
  opacity: 1;
}

.tag-item .tag-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-item .tag-status {
  flex-shrink: 0;
  color: var(--color-text-muted);
  font-size: 0.85em;
}

/* Coloured left-border accent per result type */
.tag-item--location { border-left: 3px solid var(--color-location); }
.tag-item--line     { border-left: 3px solid var(--color-line); }
.tag-item--nearby   { border-left: 3px solid var(--color-nearby); }

.tag-also-matched {
  font-size: 0.75em;
  color: var(--color-nearby);
  background: rgba(124, 58, 237, 0.08);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Folders
   ═══════════════════════════════════════════════════════════════════════════ */
#folders {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #fff;
}

.folders {
  margin-top: 4px;
}

.folder {
  border-bottom: 1px solid var(--color-border);
  background: #fff;
}

.folder-header {
  padding: 9px 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875em;
  font-weight: 500;
  color: var(--color-text);
  transition: background 0.1s;
  min-height: 44px;
}

.folder-header:hover {
  background: var(--color-hover);
}

.folder-header.active {
  background: var(--color-active);
  color: var(--color-primary);
}

.folder-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-tag-count {
  flex-shrink: 0;
  font-size: 0.8em;
  color: var(--color-text-muted);
  margin-left: 6px;
}

.folder-tags {
  border-top: 1px solid var(--color-border);
  max-height: 300px;
  overflow-y: auto;
  background: var(--color-bg-sidebar);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Tags container
   ═══════════════════════════════════════════════════════════════════════════ */
.tags {
  overflow-y: auto;
  overflow-x: hidden;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Tag popups (Leaflet)
   ═══════════════════════════════════════════════════════════════════════════ */
.tag_popup {
  font-size: 0.875em;
  color: var(--color-text);
}

.tag_popup span {
  display: block;
  margin-bottom: 4px;
}

.tag_popup a {
  color: var(--color-primary);
  text-decoration: none;
}

.tag_popup a:hover {
  text-decoration: underline;
}

.activetag {
  background-color: rgba(37, 99, 235, 0.12);
  border: 1px solid var(--color-primary);
  border-radius: 5px;
  padding: 5px;
}

.foldertag {
  cursor: pointer;
  border: 1px solid #bfdbfe;
  border-radius: 5px;
  padding: 8px 10px;
  margin-bottom: 4px;
  background: #f8fafc;
  font-size: 0.875em;
  transition: background 0.1s;
}

.foldertag:hover {
  background: var(--color-active);
}

.tag-actions select {
  margin-left: 4px;
  padding: 4px;
  border-radius: 4px;
  width: auto;
  min-width: auto;
  min-height: auto;
  margin-top: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Mobile sidebar toggle button (desktop: hidden)
   ═══════════════════════════════════════════════════════════════════════════ */
#sidebar-toggle {
  display: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Sidebar overlay backdrop
   ═══════════════════════════════════════════════════════════════════════════ */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1049;
}

#sidebar-overlay.visible {
  display: block;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Mobile  (≤ 768 px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Sidebar becomes a slide-in overlay drawer */
  #sidebar {
    position: fixed !important;
    top: var(--header-height, 60px);
    left: 0;
    bottom: var(--footer-height, 40px);
    width: min(85vw, var(--sidebar-width, 320px));
    min-width: 0 !important;
    max-width: none !important;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1050;
    overflow-y: auto;
    background: #fff;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.18);
    padding: 0 !important;
  }

  #sidebar.open {
    transform: translateX(0);
  }

  /* Map fills the full content area behind the drawer */
  #main {
    width: 100% !important;
    flex: 1 !important;
  }

  /* Floating circular toggle button */
  #sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: calc(var(--footer-height, 40px) + 12px);
    left: 12px;
    z-index: 1055;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.4);
    transition: background 0.15s, transform 0.15s;
    /* override global button styles */
    min-width: 44px;
    min-height: 44px;
    margin-top: 0;
    padding: 0;
  }

  #sidebar-toggle:hover {
    background: var(--color-primary-dark);
    transform: scale(1.05);
  }

  /* Minimap — shrink on tablet */
  .minimap-container {
    width: 160px !important;
    height: 160px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Small phone  (≤ 480 px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  /* Hide minimap to maximise map space */
  .minimap-container {
    display: none !important;
  }
}
