/* ROW layout tokens (colours come from cleargrid-theme's --cg-*) */
:root {
  --row-radius: 8px;
  --row-transition: all 0.3s ease;
  --row-header-h: 60px;
  --row-footer-h: 40px;
  --row-sidebar-w: 320px;

  /* Stacking layers. Leaflet's panes and controls use 400-1000. */
  --row-z-map-ui: 1000; /* overlays and loaders above the map controls */
  --row-z-minimap: 1002;
  --row-z-drawer: 1050; /* the mobile sidebar drawer (view.css) */
  --row-z-footer: 1100;
  --row-z-dialog: 1100; /* page dialogs that cover the footer */
  --row-z-map-panel: 1200; /* floating panels over map pages */
  --row-z-modal: 2000; /* components.css .modal and the KML style dialog */
  --row-z-scan: 9100; /* storage QR scanner flash and result */
  --row-z-top: 9999; /* toasts, review panel, confirm dialogs */
}

/* ROW colour tokens with a light and a dark value, for what --cg-* has no
   close match for. Light keeps the plugin or page value ROW has always
   shown; dark follows the same rule as cleargrid-theme (an explicit
   data-cg-scheme wins, otherwise the system setting). */
:root {
  --row-map-link: #0078a8; /* links in Leaflet popups and attribution */
  --row-map-faint: #bbb; /* disabled map buttons, popup close button */
  --row-map-subtle: #999; /* secondary text in map controls */
  --row-measure-link: #5e66cc; /* leaflet-measure's action links */
  --row-map-sprite-face: #fff; /* map buttons drawn with dark sprite icons */
  --row-review: #4a1d96; /* the "needs review" status (review.css) */
  --row-review-soft: #e2d9f3;
  --row-marker-pin: #c30b82; /* the selected-tag pin (report config editor) */
}

:root[data-cg-scheme="dark"] {
  --row-map-link: #7cc4ec;
  --row-map-faint: #6b6e72;
  --row-map-subtle: #a9abad;
  --row-measure-link: #a3a9f0;
  --row-map-sprite-face: #c9cacb;
  --row-review: #c4b5fd;
  --row-review-soft: #2a1f45;
  --row-marker-pin: #e0479e;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-cg-scheme="light"]) {
    --row-map-link: #7cc4ec;
    --row-map-faint: #6b6e72;
    --row-map-subtle: #a9abad;
    --row-measure-link: #a3a9f0;
    --row-map-sprite-face: #c9cacb;
    --row-review: #c4b5fd;
    --row-review-soft: #2a1f45;
    --row-marker-pin: #e0479e;
  }
}

* {
  box-sizing: border-box;
  font-family: var(--cg-font);
}

body {
  font-family: var(--cg-font);
  margin: 0;
  padding: 0;
  background-color: var(--cg-bg);
  color: var(--cg-text);
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
}

a {
  color: var(--cg-link);
}

a:hover {
  color: var(--cg-link-hover);
}

:focus-visible {
  outline: 2px solid var(--cg-focus-ring);
  outline-offset: 2px;
}

.header {
  display: flex;
  justify-content: space-between; /* Space between the elements */
  align-items: center; /* Vertically center the elements */
  /* Wraps when the title and the user menu or signed-out scheme toggle
     don't fit (narrow screens, and the landing page without mobile.css) */
  flex-wrap: wrap;
  row-gap: 6px;
  min-height: var(--row-header-h);
  padding: 10px 20px;
  /* The environment band (cleargrid-theme): charcoal in production, the
     environment's colour on staging, review, demo and dev. */
  background-color: var(--cg-env);
  color: var(--cg-on-env);
  width: 100%;
  box-shadow: 0 2px 5px var(--cg-shadow);
}

.leaflet-control-attribution {
  font-size: 7px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  transform: translateY(3px);
  z-index: calc(var(--row-z-map-ui) - 1); /* Ensure it's above other controls but below the header */
}

.header .home-link {
  display: flex;
  align-items: center;
}

.header .home-icon {
  display: block;
  height: 28px; /* the clearGRID logo, reversed for the dark band */
  width: auto; /* Maintain aspect ratio */
}

/* The environment badge env.js puts in [data-cg-env-slot]; empty in production. */
[data-cg-env-slot]:empty {
  display: none;
}

.header-env {
  display: inline-flex;
}

.header .title {
  font-size: 1.5em;
  font-weight: bold;
  text-align: center;
  flex-grow: 1; /* Allow the title to take up remaining space */
}

.header .user {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap; /* Prevent wrapping */
}

.header .user a {
  color: var(--cg-on-env);
  text-decoration: none;
  font-size: 0.9em;
  font-weight: lighter;
}

.header .user a:hover {
  text-decoration: underline;
}
label {
  font-weight: 600;
  display: block;
}

/* The full-width form look is opt-in: .row-input on an input, select or
   textarea, .row-button on a button, or .row-form on a container for every
   field and button in it (forms Django renders). :where() keeps these rules
   at element specificity, as they were when they applied to every element,
   so page rules still override them. */
select:where(.row-input),
input:where(.row-input),
textarea:where(.row-input),
button:where(.row-button),
:where(.row-form) select,
:where(.row-form) input,
:where(.row-form) textarea,
:where(.row-form) button {
  width: 100%;
  padding: 10px;
  margin-top: 5px;
  border: 1px solid var(--cg-control-border);
  border-radius: 8px;
}

/* Override for inputs in the Leaflet side panel */
.leaflet-panel-layers input {
  padding: 5px;
  margin: 0;
  border-radius: 4px;
}

/* Hide the fake KML load layer checkbox and name text */
.leaflet-panel-layers input#kml-loader-item {
  display: none;
}

.leaflet-panel-layers input#kml-loader-item + span {
  display: none;
}

.kml-panel-item-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
}

/* The open layer panel scrolls rather than growing past the map
   (the ancestor beats leaflet-panel-layers.css, which loads later) */
.leaflet-container .leaflet-panel-layers.expanded {
  width: 200px;
  overflow-x: hidden;
  overflow-y: auto;
}

.leaflet-panel-layers.map-layer-panel:not(.expanded) .kml-panel-item-controls,
.leaflet-panel-layers.map-layer-panel:not(.expanded) .kml-panel-load-button,
.leaflet-panel-layers.map-layer-panel:not(.expanded) .kml-panel-style-button {
  display: none !important;
}

.kml-panel-load-button,
.kml-panel-style-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--cg-border);
  border-radius: 6px;
  background: var(--cg-card);
  color: var(--cg-text);
  font-weight: 600;
  cursor: pointer;
}

.kml-panel-style-button {
  width: 32px;
}

.kml-panel-load-button:hover,
.kml-panel-style-button:hover {
  background: var(--cg-surface);
}

button:where(.row-button),
:where(.row-form) button {
  margin-top: 20px;
  background-color: var(--cg-accent);
  color: var(--cg-on-accent);
  border: none;
  cursor: pointer;
  transition: background-color 0.3s;
}
button:where(.row-button):hover,
:where(.row-form) button:hover {
  background-color: var(--cg-accent-hover);
  color: var(--cg-on-accent);
}
.page {
  width: 100%;
  height: 100%;
  flex-direction: column;
  /* display: flex; */
}
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: var(--row-z-footer); /* Increased to be above Leaflet controls */
  min-height: var(--row-footer-h);
  background-color: var(--cg-card); /* Ensure footer has background to cover content */
  border-top: 1px solid var(--cg-border); /* Add border for better separation */
}

#content {
  width: 100%;
  display: flex;
  /* Ensure content doesn't extend behind fixed footer */
  padding-bottom: 0;
  margin-bottom: 0;
  flex-direction: row;
  flex: 8 1 auto;
  flex-wrap: nowrap;
}

.sidebar {
  width: 10%;
  min-width: var(--row-sidebar-w);
  max-width: 10%;
  flex: 1 1 auto;
  display: flex;
  justify-content: flex-start;
  flex-direction: column;
  padding: 10px;
  overflow-y: auto;
}

.main {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  flex: 9 1 auto;
  height: 100%;
  position: relative;
}

h3 {
  margin-block-end: 0px;
  border-bottom: 1px solid var(--cg-control-border);
}

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

.progress_bar {
  position: fixed;
  top: 0; /* Adjust this value as needed */
  left: 0;
  width: 100%;
  padding: 10px;
  z-index: var(--row-z-map-ui);
}

.scrolling-image {
  position: absolute;
  width: 100%; /* Double the width to allow scrolling */
  height: 25px;
  top: 0;
  left: 0;
  animation: scroll-image 10s linear infinite;
}
.comment-text {
  white-space: pre-wrap;
}
@keyframes scroll-image {
  from {
    left: -10%;
  }
  to {
    left: 100%;
  }
}

/* Map pages: the map fills its container (pages add their own deltas) */
#map {
  height: 100%;
  width: 100%;
}

.tag_popup {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.tag_popup > * {
  margin: 2px;
}

.edit_pane {
  height: 100%;
}

/* Version footer styling */
.version-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  width: 100%;
  padding: 8px 20px;
  background-color: var(--cg-surface);
  border-top: 1px solid var(--cg-border);
  font-size: 0.9rem;
  color: var(--cg-muted);
}

.version-footer-item {
  flex: 1 1 0;
  font-size: 0.9rem;
}

.version-footer-item.version {
  text-align: left;
}

.version-footer-item.copyright {
  text-align: center;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 45px;
  left: 50%;
  transform: translateX(-50%);
  width: min(90vw, 420px);
  z-index: var(--row-z-top);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.toast {
  background: var(--cg-ink);
  color: var(--cg-on-ink);
  padding: 12px 20px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.4);
  border-left: 4px solid var(--cg-series-1);
  width: 100%;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  border-left-color: var(--cg-lamp-ok);
}

.toast.error {
  border-left-color: var(--cg-lamp-bad);
}

.toast.warning {
  border-left-color: var(--cg-lamp-warn);
}

.toast.info {
  border-left-color: var(--cg-series-1);
}

.toast-text {
  flex: 1;
}

.toast-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toast-ack {
  border: none;
  background: color-mix(in srgb, var(--cg-on-ink) 15%, transparent);
  color: inherit;
  width: 28px;
  height: 28px;
  margin: 0px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.2s ease;
}

.toast-ack:hover,
.toast-ack:focus-visible {
  background: color-mix(in srgb, var(--cg-on-ink) 35%, transparent);
  outline: none;
}

/* Optional link in a toast (toastManager.show(..., { link: { href, label } })).
   Toasts and their history sit on --cg-ink, so links take the lime the theme
   uses for links on dark surfaces. */
.toast-link,
.toast-history-link {
  color: var(--cg-lime);
  font-weight: 600;
  white-space: nowrap;
  text-decoration: underline;
}

.toast-link:hover,
.toast-history-link:hover {
  color: var(--cg-lime-hover);
}

.toast-history-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0px 3px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--cg-on-ink) 25%, transparent);
  background: color-mix(in srgb, var(--cg-ink) 60%, transparent);
  color: var(--cg-on-ink);
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease;
  width: auto;
  flex-shrink: 0;
  margin-top: 0;
}

.toast-history-button:hover {
  background: color-mix(in srgb, var(--cg-ink) 85%, transparent);
  border-color: color-mix(in srgb, var(--cg-on-ink) 40%, transparent);
}

.toast-history-button:focus-visible {
  outline: 2px solid var(--cg-accent);
  outline-offset: 2px;
}

.toast-history-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
}

.toast-history-count {
  font-size: 0.85rem;
  font-weight: 600;
}

.kml-style-dialog-overlay {
  position: fixed;
  inset: 0;
  background: var(--cg-backdrop);
  z-index: var(--row-z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.kml-style-dialog {
  width: min(420px, 100%);
  background: var(--cg-card);
  border-radius: 14px;
  box-shadow: 0 18px 40px var(--cg-shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.kml-style-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.kml-style-dialog-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.kml-style-dialog-header .kml-style-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.kml-style-dialog-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.kml-style-dialog-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.95rem;
}

.kml-style-dialog-body input[type="color"] {
  height: 42px;
  border: none;
  padding: 0;
  background: none;
}

.kml-style-dialog-body input[type="number"],
.kml-style-dialog-body input[type="range"] {
  width: 100%;
}

.kml-style-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.kml-style-dialog-actions button {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--cg-control-border);
  background: var(--cg-ink);
  color: var(--cg-on-ink);
  cursor: pointer;
}

.kml-style-dialog-actions button.kml-style-cancel {
  background: var(--cg-surface);
  color: var(--cg-text);
}

.kml-style-dialog-actions button:hover {
  opacity: 0.94;
}

.toast-history-panel {
  position: fixed;
  bottom: 240px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, 92vw);
  max-height: 50vh;
  background: var(--cg-ink);
  color: var(--cg-on-ink);
  border-radius: 12px;
  box-shadow: 0 25px 50px rgba(15, 23, 42, 0.5);
  border: 1px solid color-mix(in srgb, var(--cg-on-ink) 20%, transparent);
  z-index: calc(var(--row-z-top) + 1);
  display: flex;
  flex-direction: column;
}

.toast-history-panel[hidden] {
  display: none;
}

.toast-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--cg-on-ink) 20%, transparent);
  font-weight: 600;
  gap: 12px;
}

.toast-history-controls {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.toast-history-close,
.toast-history-clear {
  background: color-mix(in srgb, var(--cg-on-ink) 15%, transparent);
  border: none;
  color: inherit;
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.toast-history-close:hover,
.toast-history-clear:hover,
.toast-history-close:focus-visible,
.toast-history-clear:focus-visible {
  background: color-mix(in srgb, var(--cg-on-ink) 30%, transparent);
  outline: none;
}

.toast-history-body {
  padding: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.toast-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.toast-history-item {
  padding: 12px 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--cg-on-ink) 20%, transparent);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.toast-history-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.7;
}

.toast-history-info {
  display: flex;
  flex-direction: row-reverse;
  gap: 2px;
}

.toast-history-type {
  font-weight: 600;
}

.toast-history-meta-actions {
  display: inline-flex;
  justify-content: flex-end;
}

.toast-history-delete {
  background: none;
  border: none;
  color: inherit;
  font-size: 1rem;
  cursor: pointer;
  width: 28px;
  height: 28px;
  margin: 0;
  border-radius: 50%;
  transition: background 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toast-history-delete:hover,
.toast-history-delete:focus-visible {
  background: color-mix(in srgb, var(--cg-on-ink) 20%, transparent);
  outline: none;
}

.toast-history-message {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.toast-history-empty {
  padding: 20px;
  text-align: center;
  color: color-mix(in srgb, var(--cg-on-ink) 65%, transparent);
}

.toast-history-item.success {
  border-left: 3px solid var(--cg-lamp-ok);
}

.toast-history-item.error {
  border-left: 3px solid var(--cg-lamp-bad);
}

.toast-history-item.warning {
  border-left: 3px solid var(--cg-lamp-warn);
}

.toast-history-item.info {
  border-left: 3px solid var(--cg-series-1);
}

.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;
}


