/* Global type scale: shrink everything down for a denser, calmer UI */
:root {
  font-size: 87.5%;
}

/* Accessibility: "Larger text" toggle bumps the whole UI up a notch */
html.large-text {
  font-size: 106.25%;
}

/* Inline link-styled button (used for the text-size toggle).
   Selector is specific enough to beat Pico's default button styling. */
.header-row button.link-button {
  display: inline;
  width: auto;
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
  font: inherit;
  font-size: inherit;
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
}

.header-row button.link-button:hover {
  color: var(--primary-hover, #015580);
  background: none;
}

.header-row hgroup h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.header-row hgroup p {
  font-size: 0.85rem;
}

/* Base styles */
table {
  width: 100%;
  border-collapse: collapse;
}

.sortable-table th,
.sortable-table td {
  font-size: 0.8rem;
  padding: 0.4rem 0.5rem;
  vertical-align: top;
}

th {
  cursor: pointer;
  position: relative;
  padding-right: 20px;
}

th:hover {
  text-decoration: underline;
}

.sort-indicator {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
}

th.sort-asc .sort-indicator::after {
  content: "▲";
}

th.sort-desc .sort-indicator::after {
  content: "▼";
}

/* Layout components */
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.header-row .status-message {
  flex: 1 1 320px;
  min-width: 260px;
  max-width: 520px;
  margin: 0;
}

/* Workspace: holds the map area and the results panel side by side (desktop) */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#mapContainer {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 450px);
}

#map {
  flex: 1;
  min-height: 300px;
  max-height: calc(100vh - 450px);
  width: 100%;
}

/* Sidebar components */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
  width: 100%;
  overflow: visible;
}

.button-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: visible;
}

.button-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  overflow: visible;
}

.button-row button {
  flex: 1;
  transition: all 0.2s ease;
  position: relative;
}

.button-row button.is-disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.button-row button:hover:not(.is-disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.button-row button:active:not(.is-disabled) {
  transform: scale(0.95);
}

/* Button hint tooltips */
.button-row button[data-hint] {
  cursor: help;
}

/* Show tooltip on any button with data-hint when hovered (disabled or not) */
.button-row button[data-hint]::after {
  content: attr(data-hint);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: normal;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 10000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Arrow pointing down */
.button-row button[data-hint]::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #333;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 10000;
}

.button-row button[data-hint]:hover::after,
.button-row button[data-hint]:hover::before {
  opacity: 1;
  visibility: visible;
}

/* Visual indicator for disabled buttons with hints */
.button-row button.is-disabled[data-hint] {
  cursor: help;
}

/* Split button: primary "Select Area" + shape-picker dropdown */
.split-button {
  position: relative;
  display: flex;
  flex: 1;
}

.split-button .split-main {
  flex: 1;
  width: auto;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.split-button .split-toggle {
  flex: 0 0 auto;
  width: 2.4rem;
  padding: 0;
  margin-left: -1px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* Neutralize the generic .button-row hover/scale effects inside the split control */
.button-row .split-button button:hover:not(.is-disabled),
.button-row .split-button button:active:not(.is-disabled) {
  transform: none;
  box-shadow: none;
}

.shape-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--card-background-color, #fff);
  border: 1px solid var(--card-border-color, #ccc);
  border-radius: var(--border-radius, 6px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10000;
}

.shape-menu[hidden] {
  display: none;
}

.shape-menu li {
  margin: 0;
}

.button-row .shape-menu .shape-option {
  display: block;
  width: 100%;
  flex: 0 0 auto;
  text-align: left;
  background: none;
  border: none;
  padding: 0.5rem 0.75rem;
  border-radius: var(--border-radius, 6px);
  color: inherit;
  cursor: pointer;
}

.button-row .shape-menu .shape-option:hover,
.button-row .shape-menu .shape-option:focus-visible {
  background: var(--primary);
  color: var(--primary-inverse, #fff);
  transform: none;
  box-shadow: none;
}

/* Status message */
.status-message {
  margin: 1rem 0;
  padding: 0.75rem;
  border-radius: 4px;
  font-weight: bold;
  background-color: #e0f7fa;
  color: #00576b;
  /* Darker color for better contrast */
  text-align: center;
  transition: all 0.3s ease;
  min-height: 2.75rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.status-message .status-main {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.15rem;
}

.status-message .status-next {
  display: block;
  font-size: 0.875rem;
  font-weight: normal;
  opacity: 0.85;
  margin-top: 0.25rem;
}

.status-message.status-success {
  background-color: #d4edda;
  color: #155724;
}

.status-message.status-error {
  background-color: #f8d7da;
  color: #721c24;
}

.status-message.status-warning {
  background-color: #fff3cd;
  color: #856404;
}

.status-message.status-info {
  background-color: #e0f7fa;
  color: #00576b;
}

@keyframes flashAnim {
  0% {
    background-color: #ffeb3b;
  }

  50% {
    background-color: #fffde7;
  }

  100% {
    background-color: #e0f7fa;
  }
}

.status-message.flash {
  animation: flashAnim 1s ease;
}

/* Filter components */
.filter-container {
  margin: 0.5rem 0;
  padding: 0.5rem 0;
  position: relative;
  max-width: 300px;
}

#user-filter {
  width: 100%;
  font-size: 0.75rem;
  height: 0.9rem;
}

/* User links */
.user-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-links {
  display: flex;
  gap: 0.25rem;
}

.user-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: var(--border-radius);
  background: var(--card-background-color);
  color: var(--primary);
  transition: all 0.2s ease;
}

.user-link:hover {
  background: var(--card-border-color);
}

/* Notices */
.truncation-notice {
  margin-top: 10px;
  font-style: italic;
  color: #555;
  /* Darker for better contrast */
}

/* Toast notification for copy success */
.toast {
  visibility: hidden;
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: #fff;
  text-align: center;
  border-radius: 4px;
  padding: 16px;
  z-index: 1000;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.toast.show {
  visibility: visible;
  animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

@keyframes fadein {
  from {
    bottom: 0;
    opacity: 0;
  }

  to {
    bottom: 30px;
    opacity: 1;
  }
}

@keyframes fadeout {
  from {
    bottom: 30px;
    opacity: 1;
  }

  to {
    bottom: 0;
    opacity: 0;
  }
}

/* Footer */
footer {
  margin-top: 2rem;
  padding: 1rem 0;
  text-align: center;
  color: #555;
  /* Slightly darker for better contrast */
}

footer a {
  color: inherit;
  text-decoration: underline;
}

footer a:hover {
  color: #000;
}

/* Responsive layout */
/* Medium screens: controls sit beside the map, results stack below */
@media (min-width: 768px) {
  #mapContainer {
    flex-direction: row;
    gap: 2rem;
    height: calc(100vh - 400px);
  }

  #map {
    min-height: 400px;
    max-height: calc(100vh - 400px);
  }

  .sidebar {
    width: 200px;
    margin: 0;
  }

  .button-row {
    flex-direction: column;
  }

  .button-row button {
    width: 100%;
  }
}

/* Wide screens only: results slide in beside the map as a second pane */
@media (min-width: 1100px) {
  .workspace {
    flex-direction: row;
    align-items: stretch;
    gap: 2rem;
  }

  #mapContainer {
    flex: 1 1 55%;
    min-width: 0;
  }

  .results-panel {
    flex: 1 1 45%;
    min-width: 0;
    max-height: calc(100vh - 400px);
    overflow: auto;
    margin: 0;
    animation: slideInRight 0.3s ease;
  }
}

/* Respect users who prefer reduced motion: kill animations/transitions */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Accessibility helpers */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Focus styles for keyboard navigation */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary);
  color: white;
  padding: 8px;
  z-index: 100;
  transition: top 0.2s;
}

.skip-link:focus {
  top: 0;
}


@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideInRight {
  from {
    transform: translateX(24px);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}