/*
 * habitats/static/habitats/css/habitats.css
 *
 * Habitat-section styles for RS IS.
 * Loaded AFTER the project base CSS (bootswatch-flatly + protected_sites.css).
 * Does NOT re-import Bootstrap or redefine body/navbar — those come from the base.
 *
 * Sections:
 *   1.  CSS Variables
 *   2.  Base page layout
 *   3.  Index / Dashboard
 *   4.  Habitat List — search panel + tree
 *   5.  Habitat Detail
 *   6.  Interactive Map page  (standalone — no base template)
 *   7.  Map sidebar controls  (search, admin unit filter)
 *   8.  Map basemap / opacity control
 *   9.  Map layer groups
 *   10. Shared components
 *   11. Utilities
 */

/* ==========================================================================
   1. CSS Variables
   ========================================================================== */

:root {
  /* Brand palette */
  --hab-primary:        #21974e;
  --hab-primary-dark:   #176b37;
  --hab-primary-light:  #4db87a;
  --hab-accent:         #dbe7f7;
  --hab-accent-light:   #f3f6fb;

  /* Neutrals */
  --hab-text:           #111827;
  --hab-text-muted:     #6b7280;
  --hab-border:         #e5e7eb;
  --hab-bg:             #f5f7fa;
  --hab-bg-card:        #ffffff;
  --hab-shadow:         0 1px 2px rgba(0, 0, 0, 0.05);
  --hab-shadow-hover:   0 10px 24px rgba(0, 0, 0, 0.10);

  /* Natura 2000 gold */
  --hab-n2k:            #b5830a;
  --hab-n2k-bg:         #fff8e1;

  /* Red List badges */
  --badge-CR: #c0392b;
  --badge-EN: #e67e22;
  --badge-VU: #f1c40f;
  --badge-NT: #27ae60;
  --badge-LC: #2980b9;
  --badge-DD: #95a5a6;
  --badge-NE: #bdc3c7;

  /* Spacing / shape */
  --hab-gap:    1.5rem;
  --hab-radius: 8px;
  --hab-font:   Inter, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ==========================================================================
   2. Base page layout
   Habitat pages sit inside .wrapper > .container-fluid from the project base.
   No body/navbar overrides — those come from protected_sites.css.
   ========================================================================== */

.bg-primary {
  background-color: var(--hab-primary) !important;
}

.hab-page {
  font-family: var(--hab-font);
  color: var(--hab-text);
  background: var(--hab-bg);
  min-height: 100%;
  padding: var(--hab-gap);
}

.hab-page-header {
  margin-bottom: var(--hab-gap);
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--hab-border);
}

.hab-page-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--hab-primary-dark);
  margin: 0 0 0.25rem 0;
}

.hab-page-header p {
  color: var(--hab-text-muted);
  margin: 0;
  font-size: 0.95rem;
}

/* ==========================================================================
   3. Index / Dashboard
   ========================================================================== */

/* Hero banner */
.hab-index-hero {
  background: linear-gradient(135deg, var(--hab-primary-dark) 0%, var(--hab-primary) 60%, var(--hab-primary-light) 100%);
  border-radius: var(--hab-radius);
  color: #fff;
  padding: 2.5rem 2rem;
  margin-bottom: var(--hab-gap);
  position: relative;
  overflow: hidden;
}

.hab-index-hero::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  pointer-events: none;
}

.hab-index-hero h1 {
  font-size: 2rem;
  font-weight: 800;
  margin: 0 0 0.5rem 0;
  letter-spacing: -0.02em;
}

.hab-index-hero p {
  font-size: 1.05rem;
  opacity: 0.88;
  margin: 0 0 1.5rem 0;
  max-width: 600px;
}

.hab-index-hero-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Stats row */
.hab-stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: var(--hab-gap);
}

.hab-stat-card {
  background: var(--hab-bg-card);
  border: 1px solid var(--hab-border);
  border-radius: var(--hab-radius);
  padding: 1.25rem 1rem;
  text-align: center;
  box-shadow: var(--hab-shadow);
  transition: box-shadow 0.2s, transform 0.2s;
}

.hab-stat-card:hover {
  box-shadow: var(--hab-shadow-hover);
  transform: translateY(-2px);
}

.hab-stat-card .stat-number {
  font-size: 2rem;
  font-weight: 800;
  color: var(--hab-primary);
  line-height: 1;
  margin-bottom: 0.25rem;
}

.hab-stat-card .stat-label {
  font-size: 0.82rem;
  color: var(--hab-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Quick-link cards */
.hab-quicklinks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: var(--hab-gap);
}

.hab-quicklink-card {
  background: var(--hab-bg-card);
  border: 1px solid var(--hab-border);
  border-radius: var(--hab-radius);
  padding: 1.5rem;
  text-decoration: none;
  color: var(--hab-text);
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  box-shadow: var(--hab-shadow);
  transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
}

.hab-quicklink-card:hover {
  box-shadow: var(--hab-shadow-hover);
  transform: translateY(-2px);
  border-color: var(--hab-primary-light);
  text-decoration: none;
  color: var(--hab-text);
}

.hab-quicklink-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--hab-accent-light);
  color: var(--hab-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.hab-quicklink-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 0.25rem 0;
  color: var(--hab-primary-dark);
}

.hab-quicklink-card p {
  font-size: 0.85rem;
  color: var(--hab-text-muted);
  margin: 0;
}

/* ==========================================================================
   4. Habitat List — search panel + hierarchical tree
   ========================================================================== */

.hab-list-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--hab-gap);
  align-items: start;
}

@media (max-width: 900px) {
  .hab-list-layout { grid-template-columns: 1fr; }
}

/* Search panel */
.hab-search-panel {
  background: var(--hab-bg-card);
  border: 1px solid var(--hab-border);
  border-radius: var(--hab-radius);
  padding: 1.25rem;
  box-shadow: var(--hab-shadow);
  position: sticky;
  top: 80px;
}

.hab-search-panel h2 {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--hab-text-muted);
  margin: 0 0 1rem 0;
}

.hab-search-group {
  margin-bottom: 1rem;
}

.hab-search-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--hab-text-muted);
  margin-bottom: 0.35rem;
}

/* Search input with icon */
.hab-search-input-wrap {
  position: relative;
}

.hab-search-input-wrap .search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--hab-text-muted);
  font-size: 0.85rem;
  pointer-events: none;
  transition: opacity 0.2s;
}

.hab-search-input-wrap input {
  width: 100%;
  padding: 0.55rem 2.2rem 0.55rem 2.2rem;
  border: 1px solid var(--hab-border);
  border-radius: 6px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--hab-bg);
  color: var(--hab-text);
}

.hab-search-input-wrap input:focus {
  border-color: var(--hab-primary-light);
  box-shadow: 0 0 0 3px rgba(82, 183, 136, 0.15);
  background: #fff;
}

.hab-search-input-wrap .clear-btn {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--hab-text-muted);
  font-size: 0.85rem;
  padding: 0.2rem;
  display: none;
  line-height: 1;
}

.hab-search-input-wrap.has-value .clear-btn   { display: block; }
.hab-search-input-wrap.has-value .search-icon { opacity: 0; }

/* N2K typeahead dropdown (list pages) */
.hab-typeahead {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--hab-border);
  border-radius: 6px;
  box-shadow: var(--hab-shadow-hover);
  max-height: 220px;
  overflow-y: auto;
  z-index: 200;
  display: none;
}

.hab-typeahead.visible { display: block; }

.hab-typeahead-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--hab-border);
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.hab-typeahead-item:last-child { border-bottom: none; }

.hab-typeahead-item:hover,
.hab-typeahead-item.active { background: var(--hab-accent-light); }

.hab-typeahead-item .n2k-code {
  font-weight: 700;
  color: var(--hab-n2k);
  flex-shrink: 0;
}

.hab-typeahead-item .n2k-name {
  color: var(--hab-text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Tree panel */
.hab-tree-panel {
  background: var(--hab-bg-card);
  border: 1px solid var(--hab-border);
  border-radius: var(--hab-radius);
  box-shadow: var(--hab-shadow);
}

.hab-tree-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--hab-border);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.hab-tree-status { font-size: 0.85rem; color: var(--hab-text-muted); }
.hab-tree-actions { display: flex; gap: 0.5rem; }

.hab-tree-body {
  padding: 0.5rem 0;
  min-height: 200px;
}

/* Tree items */
.hab-tree-item { border-bottom: 1px solid transparent; }

.hab-tree-item-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.hab-tree-item-row:hover   { background: var(--hab-accent-light); }
.hab-tree-item-row.is-match { background: rgba(181, 131, 10, 0.08); }

.hab-tree-expand-icon {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--hab-text-muted);
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.hab-tree-expand-icon.expanded { transform: rotate(90deg); }
.hab-tree-expand-icon.leaf     { color: transparent; }

.hab-tree-code {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--hab-primary);
  font-family: 'Courier New', monospace;
  flex-shrink: 0;
  min-width: 70px;
}

.hab-tree-name {
  font-size: 0.9rem;
  flex: 1;
  color: var(--hab-text);
}

.hab-tree-name mark {
  background: #fff176;
  padding: 0 1px;
  border-radius: 2px;
}

.hab-tree-n2k {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--hab-n2k);
  flex-shrink: 0;
  background: var(--hab-n2k-bg);
  border-radius: 4px;
  padding: 1px 5px;
}

.hab-tree-children      { display: none; }
.hab-tree-children.open { display: block; }

/* Indentation by rank */
.hab-tree-item[data-rank="1"] > .hab-tree-item-row { padding-left: 1rem; }
.hab-tree-item[data-rank="2"] > .hab-tree-item-row { padding-left: 2rem; }
.hab-tree-item[data-rank="3"] > .hab-tree-item-row { padding-left: 3rem; }
.hab-tree-item[data-rank="4"] > .hab-tree-item-row { padding-left: 4rem; }
.hab-tree-item[data-rank="5"] > .hab-tree-item-row { padding-left: 5rem; }
.hab-tree-item[data-rank="6"] > .hab-tree-item-row { padding-left: 6rem; cursor: default; }
.hab-tree-item[data-rank="6"] > .hab-tree-item-row:hover { background: var(--hab-accent-light); }

a.hab-tree-leaf-link {
  text-decoration: none;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

a.hab-tree-leaf-link:hover .hab-tree-name {
  color: var(--hab-primary);
  text-decoration: underline;
}

/* ==========================================================================
   5. Habitat Detail
   ========================================================================== */

.hab-detail-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--hab-primary);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 1rem;
}

.hab-detail-back:hover {
  color: var(--hab-primary-dark);
  text-decoration: none;
}

.hab-detail-header {
  background: var(--hab-bg-card);
  border: 1px solid var(--hab-border);
  border-radius: var(--hab-radius);
  padding: 1.5rem;
  margin-bottom: var(--hab-gap);
  box-shadow: var(--hab-shadow);
}

.hab-detail-header h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--hab-primary-dark);
  margin: 0 0 0.5rem 0;
}

.hab-detail-meta {
  font-size: 0.88rem;
  color: var(--hab-text-muted);
}

.hab-breadcrumbs {
  display: inline-flex;
  flex-wrap: nowrap;   /* sprječava prelome */
  align-items: center;
  gap: 0.25rem;
  font-size: 0.82rem;
  margin-bottom: 0.5rem;
}


.hab-breadcrumbs a       { color: var(--hab-primary); text-decoration: none; }
.hab-breadcrumbs a:hover { text-decoration: underline; }
.hab-breadcrumbs .sep    { color: var(--hab-border); }
.hab-breadcrumbs .current { color: var(--hab-text); font-weight: 600; }

.hab-detail-main {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: var(--hab-gap);
  margin-bottom: var(--hab-gap);
  align-items: start;
}

@media (max-width: 900px) {
  .hab-detail-main { grid-template-columns: 1fr; }
}

.hab-section-block {
  background: var(--hab-bg-card);
  border: 1px solid var(--hab-border);
  border-radius: var(--hab-radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--hab-shadow);
}

.hab-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--hab-text-muted);
  margin: 0 0 0.75rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--hab-border);
}

.hab-section-list { list-style: none; margin: 0; padding: 0; }

.hab-section-list li {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--hab-border);
  font-size: 0.9rem;
}

.hab-section-list li:last-child { border-bottom: none; }

.hab-section-list .item-code {
  font-weight: 700;
  color: var(--hab-primary);
  font-family: 'Courier New', monospace;
}

.hab-section-list .item-name-local  { font-weight: 600; }

.hab-section-list .item-name-en {
  color: var(--hab-text-muted);
  font-size: 0.82rem;
}

.hab-section-list .item-relation {
  display: inline-block;
  background: var(--hab-accent-light);
  color: var(--hab-primary);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 0.8rem;
  font-weight: 700;
  margin-right: 4px;
}

.hab-detail-map-panel {
  background: var(--hab-bg-card);
  border: 1px solid var(--hab-border);
  border-radius: var(--hab-radius);
  overflow: hidden;
  box-shadow: var(--hab-shadow);
  position: sticky;
  top: 80px;
}

.hab-detail-map-title {
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--hab-text-muted);
  border-bottom: 1px solid var(--hab-border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#habitatDetailMap {
  height: 300px;
  width: 100%;
}

#habitatClcMap {
  height: 300px;
  width: 100%;
}

.hab-detail-map-stats {
  padding: 0.75rem 1rem;
  font-size: 0.82rem;
  color: var(--hab-text-muted);
  border-top: 1px solid var(--hab-border);
}

.hab-detail-map-stats strong { color: var(--hab-text); }

/* Inline map widget */
.hab-inline-map {
  height: 300px;
  width: 100%;
  border-radius: 0 0 var(--hab-radius) var(--hab-radius);
}

/* Red List badges */
.badge-redlist {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
}

.badge-CR { background: var(--badge-CR); }
.badge-EN { background: var(--badge-EN); }
.badge-VU { background: var(--badge-VU); color: #333; }
.badge-NT { background: var(--badge-NT); }
.badge-LC { background: var(--badge-LC); }
.badge-DD { background: var(--badge-DD); }
.badge-NE { background: var(--badge-NE); color: #333; }


/* Aside — static po defaultu (habitat detail ima dvije mape, ne smije biti sticky) */
.hab-page-detail-clean .hab-detail-aside {
  position: static;
  align-self: start;
  min-width: 0;
}

/* Clean detail page skin (vegType, CLC, etc.) */
.hab-page-detail-clean {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  color: #111827;
  font-family: var(--hab-font);
}

.hab-page-detail-clean .hab-page-breadcrumbs {
  margin-bottom: 0.8rem;
  font-size: 0.8rem;
  color: #6b7280;
}

.hab-page-detail-clean .hab-page-breadcrumbs a {
  color: #4b5563;
  text-decoration: none;
}

.hab-page-detail-clean .hab-page-breadcrumbs a:hover { color: #111827; }

.hab-page-detail-clean .hab-detail-back {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #1f2937;
  text-decoration: none;
}

.hab-page-detail-clean .hab-detail-back:hover { color: #111827; }

.hab-page-detail-clean .hab-detail-header {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 1.25rem 1.35rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.hab-page-detail-clean .hab-detail-header h1 {
  margin: 0 0 0.35rem 0;
  font-size: 1.55rem;
  line-height: 1.18;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #111827;
  word-break: break-word;
}

.hab-page-detail-clean .hab-detail-meta {
  font-size: 0.87rem;
  line-height: 1.45;
  color: #6b7280;
}

.hab-page-detail-clean .hab-detail-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.hab-page-detail-clean .hab-detail-main > *,
.hab-page-detail-clean #habitatDetail,
.hab-page-detail-clean #vegTypeDetail {
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.hab-page-detail-clean .hab-section-block {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 1rem 1.05rem;
  margin-bottom: 0.9rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.hab-page-detail-clean .hab-section-block:last-child { margin-bottom: 0; }

.hab-page-detail-clean .hab-section-title {
  margin: 0 0 0.75rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #eef2f7;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #486156;
}

.hab-page-detail-clean .hab-section-list {
  list-style: none;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.hab-page-detail-clean .hab-section-list li {
  padding: 0.55rem 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.93rem;
  line-height: 1.55;
  color: #1f2937;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.hab-page-detail-clean .hab-section-list li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.hab-page-detail-clean .item-code,
.hab-page-detail-clean .hab-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.85em;
  color: #2c4a3f;
}

.hab-page-detail-clean .item-name-local { color: #111827; font-weight: 600; }

.hab-page-detail-clean .item-relation {
  display: inline-block;
  background: #edf3ef;
  color: #2f6b57;
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
  font-size: 0.76rem;
  font-weight: 700;
  margin-right: 0.35rem;
}

.hab-page-detail-clean,
.hab-page-detail-clean .hab-detail-main,
.hab-page-detail-clean .hab-detail-main > * {
  overflow: visible;
}

.hab-page-detail-clean .hab-detail-aside {
  position: sticky;
  top: 20px;
  align-self: start;
  min-width: 0;
}

.hab-page-detail-clean .hab-detail-map-panel {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.hab-page-detail-clean .hab-detail-map-title {
  margin-bottom: 0.75rem;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #486156;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.hab-page-detail-clean #habitatDetailMap,
.hab-page-detail-clean #vegTypeDetailMap,
.hab-page-detail-clean #clcDetailMap,
.hab-page-detail-clean #habitatClcMap  {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 390px;
  min-height: 260px;
  border-radius: 12px;
  overflow: hidden;
  background: #f3f4f6;
}

.hab-page-detail-clean .hab-detail-map-stats {
  margin-top: 0.75rem;
  font-size: 0.84rem;
  line-height: 1.5;
  color: #6b7280;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.hab-page-detail-clean .stats-table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  table-layout: fixed;
}

.hab-page-detail-clean .stats-table th {
  padding: 0.45rem;
  border-bottom: 2px solid #e5e7eb;
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
}

.hab-page-detail-clean .stats-table td {
  padding: 0.5rem 0.45rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.hab-page-detail-clean .stats-table tr:last-child td { border-bottom: 0; }

/* Tooltips */
.hab-tooltip {
  display: inline-block;
  position: relative;
  margin-left: 0.35rem;
  width: 1rem;
  height: 1rem;
  vertical-align: middle;
  cursor: help;
  flex-shrink: 0;
  text-transform: none !important;
  letter-spacing: normal !important;
  line-height: 1 !important;
}

.hab-tooltip::before {
  content: "?";
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  background: #e5e7eb;
  color: #4b5563;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: none !important;
  letter-spacing: normal !important;
  line-height: 1 !important;
}

.hab-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #111827;
  color: #ffffff;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  text-transform: none !important;
  letter-spacing: normal !important;
  white-space: normal;
  width: 220px;
  max-width: min(220px, 70vw);
  text-align: left;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 9999;
}

.hab-tooltip:hover::after,
.hab-tooltip:hover::before { opacity: 1; }

.hab-tooltip-left::after {
  right: auto;
  left: 50%;
  transform: translateX(-100%);
}

.th-num {
  text-align: right !important;
  text-transform: none !important;
}

.stats-table th .hab-tooltip,
.stats-table th .hab-tooltip::before,
.stats-table th .hab-tooltip::after {
  text-transform: none !important;
  letter-spacing: normal !important;
}

/* Detail responsive */
@media (max-width: 1024px) {
  .hab-page-detail-clean { max-width: 100%; padding: 0.95rem 0.9rem 1.75rem; }
  .hab-page-detail-clean .hab-detail-main { grid-template-columns: 1fr; }
  .hab-page-detail-clean .hab-detail-aside { position: static; top: auto; }
}

@media (max-width: 640px) {
  .hab-page-detail-clean { padding: 0.8rem 0.75rem 1.5rem; }
  .hab-page-detail-clean .hab-page-breadcrumbs { font-size: 0.76rem; line-height: 1.4; }
  .hab-page-detail-clean .hab-detail-back { font-size: 0.85rem; margin-bottom: 0.85rem; }
  .hab-page-detail-clean .hab-detail-header { padding: 0.95rem 0.9rem; }
  .hab-page-detail-clean .hab-detail-header h1 { font-size: 1.22rem; }
  .hab-page-detail-clean .hab-detail-meta { font-size: 0.82rem; }
  .hab-page-detail-clean .hab-section-block,
  .hab-page-detail-clean .hab-detail-map-panel { padding: 0.82rem 0.85rem; border-radius: 12px; }
  .hab-page-detail-clean .hab-section-list li { font-size: 0.88rem; line-height: 1.45; }
  .hab-page-detail-clean #habitatDetailMap,
  .hab-page-detail-clean #vegTypeDetailMap,
  .hab-page-detail-clean #clcDetailMap { height: 300px; min-height: 220px; }
}

@media (max-width: 470px) {
  .hab-page-detail-clean { padding: 0.7rem 0.55rem 1.25rem; }
  .hab-page-detail-clean .hab-detail-header,
  .hab-page-detail-clean .hab-section-block,
  .hab-page-detail-clean .hab-detail-map-panel,
  .hab-page-detail-clean .hab-detail-main,
  .hab-page-detail-clean .hab-detail-main > * { width: 100%; max-width: 100%; min-width: 0; }
  .hab-page-detail-clean .hab-detail-header { padding: 0.85rem 0.8rem; }
  .hab-page-detail-clean .hab-detail-header h1 { font-size: 1.08rem; line-height: 1.2; }
  .hab-page-detail-clean .hab-detail-main { gap: 0.85rem; }
  .hab-page-detail-clean .hab-section-block,
  .hab-page-detail-clean .hab-detail-map-panel { padding: 0.78rem; }
  .hab-page-detail-clean .hab-section-title,
  .hab-page-detail-clean .hab-detail-map-title { font-size: 0.67rem; letter-spacing: 0.06em; }
  .hab-page-detail-clean .hab-section-list li,
  .hab-page-detail-clean .hab-detail-map-stats { font-size: 0.84rem; }
  .hab-page-detail-clean #habitatDetailMap,
  .hab-page-detail-clean #vegTypeDetailMap,
  .hab-page-detail-clean #clcDetailMap { height: 250px; min-height: 190px; }
  .hab-page-detail-clean .stats-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
}

/* ==========================================================================
   6. Interactive Map page  (standalone — has its own <html>/<body>)
   habitat_map.html does NOT use the project base template.
   ========================================================================== */

/* Full-viewport reset for the map page */
.map-page html,
.map-page body {
  height: 100%;
  overflow: hidden;
  font-family: var(--hab-font);
  background: var(--hab-bg);
}

/* Top bar */
.map-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  background: var(--hab-primary-dark);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

.map-topbar a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: color 0.15s;
}

.map-topbar a:hover      { color: #fff; }
.map-topbar-title        { font-size: 0.95rem; font-weight: 700; color: #fff; }
.map-topbar-sep          { color: rgba(255,255,255,0.3); }

/* Main flex layout */
.map-layout {
  position: fixed;
  top: 48px;
  left: 0; right: 0; bottom: 0;
  display: flex;
  overflow: hidden;
}

/* Map canvas */
.hab-map-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
}

#hab-leaflet-map {
  flex: 1;
  height: 100%;
  min-width: 0;
}

/* Full-map loading overlay */
#hab-map-loading {
  position: absolute;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.4);
  font-size: 3.4rem;
  color: var(--hab-primary);
}

/* ==========================================================================
   7. Map sidebar controls
   ========================================================================== */

.map-sidebar {
  width: 480px;
  flex-shrink: 0;
  background: var(--hab-bg-card);
  border-right: 1px solid var(--hab-border);
  display: flex;
  flex-direction: column;
  overflow: visible;   /* needed so typeahead dropdown escapes the sidebar */
  z-index: 10;
}

.map-sidebar-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--hab-border);
  flex-shrink: 0;
  overflow: visible;
}

.map-sidebar-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--hab-primary-dark);
  margin: 0 0 0.6rem 0;
}

/* Spatial context banner — shows current map extent (RS or admin unit) */
.map-spatial-context {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.6rem;
  background: var(--hab-accent-light);
  border: 1px solid var(--hab-border);
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--hab-text);
  line-height: 1.35;
}

.map-spatial-context i {
  color: var(--hab-primary);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.map-spatial-context-label {
  color: var(--hab-text-muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: block;
}

.map-spatial-context-value {
  font-weight: 700;
  color: var(--hab-primary-dark);
}

/* Tabs */
.map-tabs {
  display: flex;
  border-bottom: 1px solid var(--hab-border);
  flex-shrink: 0;
}

.map-tab {
  flex: 1;
  padding: 0.55rem 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--hab-text-muted);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.map-tab.active {
  color: var(--hab-primary);
  border-bottom-color: var(--hab-primary);
}

.map-tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
}

.map-tab-content.active { display: block; }

/* Map search inputs (general + N2K) */
.map-sidebar .hab-search-group { position: relative; }

/* Admin unit filter block */
.map-filter-block {
  margin-top: 0.75rem;
  position: relative;
  overflow: visible;
}

.map-filter-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--hab-text-muted);
}

/* Shared search-wrap used for admin unit input */
.map-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  border: 1px solid var(--hab-border);
  border-radius: 8px;
  background: #fff;
  min-height: 40px;
}

.map-search-input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 0.65rem 2.2rem 0.65rem 0.75rem;
  font-size: 0.85rem;
  color: var(--hab-text);
}

.map-search-input::placeholder { color: var(--hab-text-muted); }

.map-search-clear {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.7rem;
  height: 1.7rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--hab-text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.map-search-clear:hover {
  background: var(--hab-accent-light);
  color: var(--hab-primary);
}

/* Admin unit typeahead — absolutely positioned, escapes sidebar overflow */
#mapAdminUnitWrap {
  position: relative;
  z-index: 30;
}

#mapAdminUnitTypeahead {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 9999;
  display: none;
  border: 1px solid var(--hab-border);
  border-radius: 6px;
  background: #fff;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 8px 22px rgba(0,0,0,0.14);
}

#mapAdminUnitTypeahead.visible { display: block; }

/* Layer list items */
.layer-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--hab-border);
  font-size: 0.83rem;
}

.layer-item:last-child { border-bottom: none; }

.layer-swatch {
  width: 13px; height: 13px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.12);
}

.layer-name  { flex: 1; }
.layer-count { font-size: 0.73rem; color: var(--hab-text-muted); }

/* Results list */
.result-list { list-style: none; margin: 0; padding: 0; }

.result-list li {
  padding: 0.4rem;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.83rem;
  border: 1px solid transparent;
  transition: background 0.12s;
}

.result-list li:hover {
  background: var(--hab-accent-light);
  border-color: var(--hab-border);
}

.result-code {
  font-weight: 700;
  color: var(--hab-primary);
  font-size: 0.76rem;
  font-family: 'Courier New', monospace;
}

/* Stats table */
.stats-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }

.stats-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--hab-text-muted);
  padding: 0.35rem 0.4rem;
  border-bottom: 2px solid var(--hab-border);
  text-align: left;
}

.stats-table td {
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid var(--hab-border);
}

.stats-table tr:last-child td { border-bottom: none; }

/* Map mobile layout */
@media (max-width: 700px) {
  .map-sidebar {
    width: 100%;
    position: absolute;
    bottom: 0; left: 0; right: 0; top: auto;
    height: 40vh;
    border-right: none;
    border-top: 2px solid var(--hab-border);
  }
  .map-layout        { flex-direction: column; }
  #hab-leaflet-map   { flex: none; height: 60vh; }
}

/* ==========================================================================
   8. Map basemap / opacity control  (Leaflet custom control)
   ========================================================================== */

.map-tools-control {
  position: relative;
  background: transparent;
  border: none;
  box-shadow: none;
  overflow: visible;
}

.map-tools-toggle {
  width: 48px;
  height: 48px;
  border: 2px solid rgba(0,0,0,0.2);
  background: #fff;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  color: var(--hab-primary-dark);
  transition: background 0.18s ease, color 0.18s ease;
}

.map-tools-toggle:hover {
  background: #f8fafc;
  color: var(--hab-primary);
}

.map-tools-toggle.active {
  background: var(--hab-primary);
  color: #fff;
}

.map-tools-panel {
  position: absolute;
  top: 0;
  right: 58px;
  width: 260px;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 16px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.16);
  padding: 0.95rem 1rem 1rem;
  z-index: 9999;
}

.map-basemap-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.map-basemap-btn {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 0.3rem !important;
  width: auto !important;
  height: auto !important;
  min-height: 52px !important;
  padding: 0.5rem !important;
  border: 1px solid var(--hab-border) !important;
  border-radius: 10px !important;
  background: #f9fafb !important;
  cursor: pointer !important;
  font-size: 0.75rem !important;
  font-weight: 600 !important;
  color: var(--hab-text) !important;
  text-align: center !important;
  box-sizing: border-box !important;
}

.map-basemap-btn:hover {
  border-color: var(--hab-primary-light) !important;
  background: #f3f8f5 !important;
}

.map-basemap-btn.active {
  border-color: var(--hab-primary) !important;
  background: #edf6f1 !important;
  color: var(--hab-primary-dark) !important;
}

.map-basemap-btn.active i {
  color: var(--hab-primary) !important;
}

.map-basemap-btn i {
  font-size: 1.1rem !important;
  color: var(--hab-text-muted) !important;
  width: auto !important;
  height: auto !important;
}

.map-tools-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--hab-text-muted);
  margin: 0 0 0.55rem 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.map-opacity-value {
  font-weight: 700;
  color: var(--hab-primary);
  font-size: 0.78rem;
}

.map-opacity-slider {
  width: 100%;
  margin-top: 0.15rem;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  margin-bottom: 0.8rem;
}

.map-opacity-slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--hab-primary-light), var(--hab-primary));
}

.map-opacity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  margin-top: -5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--hab-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

.map-opacity-slider::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--hab-primary-light), var(--hab-primary));
}

.map-opacity-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--hab-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

.map-tools-panel::after {
  content: "";
  position: absolute;
  top: 16px;
  right: -7px;
  width: 14px;
  height: 14px;
  background: rgba(255,255,255,0.98);
  border-top: 1px solid rgba(17,24,39,0.08);
  border-right: 1px solid rgba(17,24,39,0.08);
  transform: rotate(45deg);
}

@media (max-width: 700px) {
  .map-tools-panel {
    right: 0;
    top: 56px;
    width: 250px;
  }
  .map-tools-panel::after { display: none; }
  .map-basemap-btns { grid-template-columns: 1fr; }
}

/* ==========================================================================
   9. Map layer groups
   ========================================================================== */

/* ==========================================================================
   Layer groups — collapsible sections with custom checkboxes
   ========================================================================== */

/* Custom checkbox — hides native, shows styled square with green check */
.hab-custom-cb {
  position: relative;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
}

.hab-custom-cb input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}

.hab-custom-cb-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--hab-border);
  border-radius: 0;
  background: #fff;
  transition: border-color 0.15s, background 0.15s;
  pointer-events: none;
  background-size: 14px 14px;
}

.hab-custom-cb input:checked + .hab-custom-cb-box {
  border-color: var(--hab-primary);
  background: #fff;
  /* SVG checkmark as background — pixel-perfect, no transform tricks */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpolyline points='1.5,6 4.5,9.5 10.5,2.5' fill='none' stroke='%232f6b57' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 14px 14px;
}

.hab-custom-cb input:indeterminate + .hab-custom-cb-box {
  border-color: var(--hab-primary-light);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cline x1='2' y1='6' x2='10' y2='6' stroke='%235f8f7b' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 10px 10px;
}

.hab-custom-cb:hover .hab-custom-cb-box {
  border-color: var(--hab-primary-light);
}

/* Group container */
.hab-layer-group {
  margin-bottom: 0.25rem;
  background: #fff;
}

/* Group header row */
.hab-layer-group-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.25rem;
  border-radius: 5px;
  transition: background 0.12s;
}

.hab-layer-group-header:hover {
  background: var(--hab-accent-light);
}

.hab-layer-group-left {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
}

.hab-layer-group-right {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* Collapse toggle button — chevron arrow */
.hab-layer-group-collapse {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hab-text-muted);
  flex-shrink: 0;
  transition: color 0.15s;
}

.hab-layer-group-collapse:hover { color: var(--hab-primary); }

.hab-layer-group-collapse i {
  font-size: 0.65rem;
  transition: transform 0.2s;
}

.hab-layer-group-collapse[aria-expanded="true"] i {
  transform: rotate(90deg);
}

/* Group title */
.hab-layer-group .hab-section-title {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--hab-text);
  text-transform: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Group body — indented items */
.hab-layer-group-body {
  padding: 0.1rem 0 0.4rem 2.4rem;
}

/* Individual layer row */
.layer-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.3rem 0.25rem;
  border-bottom: none;
  border-radius: 4px;
  transition: background 0.12s;
  cursor: pointer;
}

.layer-item:hover { background: var(--hab-accent-light); }

.layer-swatch {
  width: 12px;
  height: 12px;
  border-radius: 0;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.10);
}

.layer-name {
  flex: 1;
  font-size: 0.82rem;
  color: var(--hab-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* layer-count hidden via JS — CSS fallback */
.layer-count { display: none; }

/* ==========================================================================
   10. Shared components
   ========================================================================== */

/* Buttons */
.hab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
}

.hab-btn:active { transform: scale(0.97); }

.hab-btn-primary { background: var(--hab-primary); color: #fff; }

.hab-btn-primary:hover {
  background: var(--hab-primary-dark);
  color: #fff;
  text-decoration: none;
}

.hab-btn-outline {
  background: transparent;
  color: var(--hab-primary);
  border: 1.5px solid var(--hab-primary-light);
}

.hab-btn-outline:hover {
  background: var(--hab-accent-light);
  text-decoration: none;
  color: var(--hab-primary-dark);
}

.hab-btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

/* Loading spinner */
.hab-loading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 2rem 1.5rem;
  color: var(--hab-text-muted);
  font-size: 0.9rem;
  justify-content: center;
}

.hab-loading .spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--hab-border);
  border-top-color: var(--hab-primary);
  border-radius: 50%;
  animation: hab-spin 0.7s linear infinite;
}

@keyframes hab-spin { to { transform: rotate(360deg); } }

/* Empty state */
.hab-empty {
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--hab-text-muted);
  font-size: 0.9rem;
}

.hab-empty i {
  font-size: 2rem;
  display: block;
  margin-bottom: 0.75rem;
  opacity: 0.4;
}

/* Breadcrumbs */
.hab-page-breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  margin-bottom: 1rem;
  color: var(--hab-text-muted);
}

.hab-page-breadcrumbs a       { color: var(--hab-primary); text-decoration: none; }
.hab-page-breadcrumbs a:hover { text-decoration: underline; }
.hab-page-breadcrumbs .sep    { opacity: 0.4; }

/* ==========================================================================
   11. Utilities
   ========================================================================== */

.hab-text-muted { color: var(--hab-text-muted); }
.hab-text-small { font-size: 0.82rem; }
.hab-mono       { font-family: 'Courier New', monospace; }
.hab-bold       { font-weight: 700; }
.hab-mt-1       { margin-top: 1rem; }
.hab-mb-1       { margin-bottom: 1rem; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Map page — embedded in base.html
   .container-fluid iz protected-sites.css već ima:
     height: calc(100vh - 120px)  (50px navbar + 70px footer)
     overflow-y: auto
   Mapa popunjava tu visinu u potpunosti.
   ========================================================================== */

.hab-map-page {
  /* Popuni cijelu visinu container-fluid i sakri scroll — mapa ima vlastiti scroll */
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Flex row: sidebar + mapa, popunjava cijelu visinu .hab-map-page */
.hab-map-inner-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0; /* kritično za flex child da ne naraste van roditelja */
}

/* Sidebar unutar embedded mape — ista širina kao standalone verzija */
.hab-map-inner-layout .map-sidebar {
  height: 100%;
}

/* Map wrap unutar embedded mape */
.hab-map-inner-layout .hab-map-wrap {
  height: 100%;
}

.hab-map-inner-layout #hab-leaflet-map {
  width: 100%;
  height: 100%;
}

@media (max-width: 700px) {
  .hab-map-page {
    position: relative;
  }

  .hab-map-inner-layout {
    flex-direction: row;
    position: relative;
  }

  .hab-map-inner-layout .hab-map-wrap {
    height: 100%;
    min-height: 0;
  }

  .hab-map-inner-layout .hab-map-wrap,
    .hab-map-inner-layout #hab-leaflet-map {
      min-height: 0;
  }

  .hab-map-inner-layout .map-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(100%, 420px);
    height: 100%;
    border-right: 1px solid var(--hab-border);
    border-top: 0;
    background: var(--hab-bg-card);
    z-index: 1200;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 6px 0 24px rgba(0,0,0,0.12);
  }

  .hab-map-page.is-panel-open .map-sidebar {
    transform: translateX(0);
  }

  .hab-map-mobile-toolbar {
    display: block;
    position: absolute;
    right: 0.75rem;
    bottom: 0.75rem;
    z-index: 1100;
  }

  .hab-map-page.is-panel-open .hab-map-mobile-toolbar {
    display: none;
  }

  .map-sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .hab-map-sidebar-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.35);
    z-index: 1150;
  }

  .hab-map-page.is-panel-open .hab-map-sidebar-backdrop {
    display: block;
  }

  #hab-map-loading {
    z-index: 1300;
  }
}

.map-sidebar-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.map-sidebar-close {
  display: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--hab-text-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.map-sidebar-close:hover {
  background: var(--hab-accent-light);
  color: var(--hab-primary);
}

.hab-map-mobile-toolbar {
  display: none;
}

.hab-map-mobile-btn {
  border: 0;
  border-radius: 999px;
  background: var(--hab-primary);
  color: #fff;
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
  cursor: pointer;
}

.hab-map-sidebar-backdrop {
  display: none;
}

/* ==========================================================================
   CLC hierarchical layer list — 3 levels
   ========================================================================== */

/* Level 1 — top category (e.g. "Šumska i poluprirodna područja") */
.hab-clc-l1 {
  margin-bottom: 0.15rem;
}

.hab-clc-l1-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.25rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s;
}

.hab-clc-l1-header:hover { background: var(--hab-accent-light); }

.hab-clc-l1-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--hab-text);
}

/* Level 1 body — indented */
.hab-clc-l1-body {
  padding-left: 1.1rem;
}

/* Level 2 — sub-category (e.g. "Šume") */
.hab-clc-l2 {
  margin-bottom: 0.1rem;
}

.hab-clc-l2-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.25rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s;
}

.hab-clc-l2-header:hover { background: var(--hab-accent-light); }

.hab-clc-l2-title {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--hab-text-muted);
}

/* Level 2 body — further indented */
.hab-clc-l2-body {
  padding-left: 1.0rem;
}

/* Level 3 items inherit .layer-item styles */

/* ==========================================================================
   Habitat list — clean layout (search above tree)
   ========================================================================== */

.hab-list-search-bar {
  background: #f0f4f1;          /* malo svjetlija od var(--hab-surface) */
  border: 1px solid var(--hab-border);
  border-radius: 10px;
  padding: 1.1rem 1.25rem 0.9rem;
  margin-bottom: 1.25rem;
}

.hab-list-search-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}


/* Search inputs inside the bar get white background to contrast with #f0f4f1 */
/* Inputi u search baru: bijela pozadina, nešto tamniji border */
.hab-list-search-bar .hab-search-input-wrap input {
  background: #ffffff;
  border-color: #adc4b5;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.hab-list-search-bar .hab-search-input-wrap input:focus {
  border-color: var(--hab-primary);
  box-shadow: 0 0 0 3px rgba(45,106,79,0.12);
  background: #ffffff;
}

/* Actions row: status left, buttons right */
.hab-list-search-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  border-top: 1px solid var(--hab-border);
  padding-top: 0.65rem;
  margin-top: 0.1rem;
}

.hab-list-search-actions .hab-tree-status {
  font-size: 0.82rem;
  color: var(--hab-text-muted);
}

.hab-list-search-actions .hab-tree-actions {
  margin-left: auto;
}

.hab-list-tree-wrap {
  background: var(--hab-surface);
  border: 1px solid var(--hab-border);
  border-radius: 10px;
  padding: 0.5rem 0;
  min-height: 200px;
}

/* Remove border from tree body when inside wrap */
.hab-list-tree-wrap .hab-tree-body {
  border: none;
  border-radius: 0;
  padding: 0;
}

/* Dropdown — full width na malim ekranima */
@media (max-width: 991px) {
  .dropdown {
    position: static;
  }

  .dropdown-menu {
    position: fixed !important;
    top: 56px !important;   /* visina navbara — podesi ako treba */
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    border-radius: 0;
    margin-top: 0;
    z-index: 9999 !important;
  }

  .dropdown-divider {
    border-top: 1px solid rgba(0, 0, 0, 0.2) !important;
    margin: 0 !important;
  }
}



/* Override protected-sites sidebar active link color */
#sidebar-search ul li.active > a,
a[aria-expanded="true"],
#sidebar-info ul li.active > a,
#sidebar-pslist ul li.active > a {
  background: var(--hab-primary-light) !important;
}

/* Override navbar secondary hover color */
.navbar-brand.secondary:hover {
  background-color: var(--hab-primary-light) !important;
}

/* Override dropdown item hover/active colors */
.dropdown-item:hover,
.dropdown-item:focus {
  color: #fff !important;
  background-color: var(--hab-primary-light) !important;
}

.dropdown-item.active,
.dropdown-item:active {
  color: #fff !important;
  background-color: var(--hab-primary-light) !important;
}

/* ==========================================================================
   Navbar dropdown — konsolidovana responsive pravila
   ========================================================================== */

@media (min-width: 992px) {
  .navbar-brand.about-link                { display: inline-block !important; }
  .navbar-brand.nav-link-habitats         { display: inline-block !important; }
  .navbar-brand.nav-link-map              { display: inline-block !important; }
  .navbar-brand.secondary-btn             { display: none !important; }
  .navbar-brand.secondary.dropdown-toggle { display: inline-block !important; }
  .dropdown-sm                            { display: none; }
  .dropdown-divider {
    border-top: 1px solid rgba(0, 0, 0, 0.2) !important;
    margin: 0 !important;
  }
  .dropdown-menu {
    padding: 0;
    background-color: transparent;
    border: 0;
    font-family: Montserrat, sans-serif;
    font-weight: 700;
    font-size: 12px;
    box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
    background-clip: padding-box;
    left: auto;
    right: 0;
  }
}

@media (max-width: 991px) {
  .navbar-brand.about-link                { display: none !important; }
  .navbar-brand.nav-link-habitats         { display: none !important; }
  .navbar-brand.nav-link-map              { display: none !important; }
  .navbar-brand.secondary-btn             { display: inline-block !important; color: rgba(255,255,255,0.75); }
  .navbar-brand.secondary.dropdown-toggle { display: none !important; }
  .dropdown-sm                            { display: block !important; }
}

.navbar-brand.secondary {
  margin-right: 0;
}

.hab-section-list a:hover .item-name-local,
.hab-section-list a:hover {
  color: var(--hab-primary);
}

/* ==========================================================================
   Map toggle (habitat detail — veg vs CLC)
   ========================================================================== */

.hab-map-toggle {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.hab-map-toggle-btn {
  flex: 1;
  padding: 0.45rem 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1.5px solid var(--hab-border);
  border-radius: 6px;
  background: var(--hab-bg);
  color: var(--hab-text-muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.hab-map-toggle-btn:hover {
  border-color: var(--hab-primary-light);
  color: var(--hab-primary);
  background: var(--hab-accent-light);
}

.hab-map-toggle-btn.active {
  background: var(--hab-primary);
  border-color: var(--hab-primary);
  color: #fff;
}

/* Sticky aside — samo za stranice s jednom mapom */
.hab-aside-sticky {
  position: sticky;
  top: 70px;
  align-self: start;
}

/* ------------------------------------------------------------------
   QUICK LINK CARDS — PRIMARY
------------------------------------------------------------------ */

.hab-quicklink-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;

  padding: 1.75rem 1.5rem;
  border-radius: 10px;
  background: #fff;

  transition: all 0.2s ease;
}

.hab-quicklink-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
}

.hab-quicklink-card i {
  font-size: 2.3rem;
  color: var(--hab-primary);
  margin-bottom: 0.6rem;
}

.hab-quicklink-card h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #000;
  margin: 0 0 0.45rem 0;
}

.hab-quicklink-card p {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--hab-text-muted);
  margin: 0;
}


/* ------------------------------------------------------------------
   EXTERNAL LINKS SECTION
------------------------------------------------------------------ */

.hab-external-links-section {
  margin-top: 1.5rem;
}


/* ------------------------------------------------------------------
   QUICK LINK CARDS — SECONDARY (6-column compact)
------------------------------------------------------------------ */

.hab-quicklinks-secondary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.hab-quicklink-card-secondary {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  padding: 0.8rem;
  border-radius: 8px;
  background: #fff;
  text-align: center;

  transition: all 0.18s ease;
}

.hab-quicklink-card-secondary:hover {
  background: #f8fafc;
  transform: translateY(-1px);
}

.hab-quicklink-card-secondary i {
  font-size: 1.1rem;
  color: var(--hab-primary);
  margin-bottom: 0.3rem;
}

.hab-quicklink-card-secondary h2 {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}

/* sakrij opis za compact view */
.hab-quicklink-card-secondary p {
  display: none;
}


/* ------------------------------------------------------------------
   RESPONSIVE GRID
------------------------------------------------------------------ */

@media (max-width: 1200px) {
  .hab-quicklinks-secondary {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .hab-quicklinks-secondary {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 576px) {
  .hab-quicklinks-secondary {
    grid-template-columns: 1fr;
  }
}

/* =========================================================
   MOBILE MAP PANEL (SIGURNA VARIJANTA)
========================================================= */

/* roditelj mora biti positioned */
.hab-map-page {
  position: relative;
}

/* dugme (po defaultu sakriveno) */
.hab-map-mobile-toolbar {
  display: none;
}

/* =========================================================
   MOBILE ONLY
========================================================= */
@media (max-width: 700px) {

  .hab-map-mobile-toolbar {
    display: block !important;
    position: absolute;
    right: 12px;
    bottom: 22px;
    z-index: 10030;
  }

  .hab-map-page.is-panel-open .hab-map-mobile-toolbar {
    display: none !important;
  }

  .hab-map-mobile-btn {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 999px;
    background: var(--hab-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(0,0,0,0.22);
    cursor: pointer;
    padding: 0;
  }

  .hab-map-mobile-btn i {
    font-size: 1rem;
    line-height: 1;
  }

  .hab-map-mobile-btn span {
    display: none;
  }

  .hab-map-sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 10010;
    display: none;
  }

  .hab-map-page.is-panel-open .hab-map-sidebar-backdrop {
    display: block;
  }

  .map-sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 90%;
    max-width: 420px;
    height: 100%;
    background: #fff !important;
    opacity: 1 !important;
    z-index: 10020 !important;
    box-shadow: 8px 0 24px rgba(0,0,0,0.18);

    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .hab-map-page.is-panel-open .map-sidebar {
    transform: translateX(0);
  }

  .map-sidebar-close {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--hab-text-muted);
    font-size: 18px;
    cursor: pointer;
  }

  .map-sidebar-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .hab-map-wrap {
    height: calc(100vh - 120px);
  }
}

.source-reference {
  font-size:0.8rem;
  color:var(--hab-text-muted);
  padding:1rem 1.5rem 0.75rem;
  border-top:1px solid var(--hab-border);
}

.hab-cl-label {
  font-weight: 700;
  color: var(--hab-primary);
}