/* === Global Styles === */
:root {
  --pico-border-radius: 0.25rem;
}

[type="search"] {
  --pico-border-radius: 0.25rem;
}

/* === Utilities === */
.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip link - standard a11y pattern */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  padding: 0.5rem 1rem;
  background: var(--pico-primary);
  color: var(--pico-primary-inverse);
  z-index: 1000;
  text-decoration: none;
}

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

/* === Site Header Nav === */
nav[data-theme="dark"] {
  background: var(--pico-primary-background);
}

/* Ensure nav links have sufficient contrast on dark background */
nav[data-theme="dark"] a:not([role="button"]) {
  color: var(--pico-primary-inverse);
}

nav[data-theme="dark"] summary {
  color: var(--pico-primary-inverse);
}

nav .logo {
  height: 50px;
}

/* === Filters Sidebar === */
.filters-sidebar {
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--pico-card-background-color);
  order: -1;  /* Display before results (which come first in DOM for tab order) */
}

/* Results section - comes first in DOM for keyboard nav, displayed after sidebar */
.directory-results {
  order: 0;
}

.filters {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.filters-scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--pico-spacing);
}

.filters-footer {
  padding: var(--pico-spacing);
  border-top: 1px solid var(--pico-muted-border-color);
  background: var(--pico-card-background-color);
}

/* Mobile filter controls - hidden by default */
.mobile-filter-toggle,
.mobile-filter-close,
.mobile-filter-backdrop {
  display: none;
}

/* === Filter Controls === */
.filter-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.4rem;
  margin: 0;
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: var(--pico-border-radius);
  transition: background-color 0.1s;
}

.filter-item:hover {
  background: var(--pico-muted-border-color);
}

.filter-item input[type="checkbox"] {
  margin: 0;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

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

.filter-item .filter-count {
  font-size: 0.7rem;
  opacity: 0.5;
  flex-shrink: 0;
}

.filter-item:has(input:checked) {
  background: var(--pico-primary-focus);
}

.filter-item:has(input:checked) .filter-label {
  font-weight: 500;
}

.filter-item:has(input:checked) .filter-count {
  opacity: 0.8;
}

/* === Stream Icon Checkboxes === */
.stream-icons {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.stream-icon {
  position: relative;
  cursor: pointer;
  margin: 0;
  padding: 0;
}

.stream-icon input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.stream-icon img {
  width: 48px;
  height: 48px;
  border-radius: var(--pico-border-radius);
  object-fit: cover;
  opacity: 0.5;
  filter: grayscale(40%);
  transition: all 0.15s ease;
  border: 2px solid transparent;
}

.stream-icon:hover img {
  opacity: 0.75;
  filter: grayscale(20%);
}

.stream-icon input:checked + img {
  opacity: 1;
  filter: none;
  border-color: var(--pico-primary);
  box-shadow: 0 0 0 2px var(--pico-primary-focus);
}

/* Focus styles for keyboard navigation (a11y) */
.stream-icon:focus {
  outline: 2px solid var(--pico-primary);
  outline-offset: 2px;
  border-radius: var(--pico-border-radius);
}

.stream-icon:focus:not(:focus-visible) {
  outline: none;
}

/* === Filter Options (non-icon checkboxes) === */
.filter-options {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.35rem;
  max-height: 300px;
  overflow-y: auto;
}

/* === JS-Applied Filter Classes === */
.company-item.filter-hidden {
  display: none !important;
}

/* === No Results Message === */
.no-results {
  display: none;
  text-align: center;
  opacity: 0.7;
  padding: 2rem;
}

/* === Search Highlighting (CSS Custom Highlight API) === */
::highlight(search-results) {
  background-color: var(--pico-primary-focus);
  color: inherit;
}

/* === Taxonomy Pages === */
/* Taxonomy term cards with optional icons */
.taxonomy-card {
  text-align: center;
}

.taxonomy-card a,
.taxonomy-card a:hover {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: inherit;
}

.taxonomy-card .taxonomy-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.taxonomy-card .taxonomy-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: var(--pico-border-radius);
}

.taxonomy-card .taxonomy-map-thumb {
  width: 100%;
  height: auto;
  border-radius: var(--pico-border-radius);
  object-fit: cover;
}

/* Taxonomy term page - embedded map (sticky sidebar) */
.taxonomy-map {
  position: sticky;
  top: var(--pico-spacing);
  height: calc(100vh - 2 * var(--pico-spacing));
}

.taxonomy-map iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: var(--pico-border-radius);
}

/* === Company Cards === */
.company-card {
  display: block;
  text-decoration: none;
  color: inherit;
  height: 100%;
  width: 100%;
}

.company-card article {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  height: 100%;
  padding: 1rem;
  transition: background-color 0.15s;
  background: var(--pico-card-background-color);
  border-radius: var(--pico-border-radius);
}

.company-card:hover article {
  background-color: var(--pico-card-sectioning-background-color);
}

.company-card .logo-area {
  height: 60px;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.company-card .logo-area img {
  max-width: 100%;
  max-height: 60px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.company-card .logo-area .initials {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--pico-muted-color);  /* Use muted color instead of opacity */
}

.company-card .name {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  font-weight: bold;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.company-card .badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.2rem;
  margin-bottom: 0.35rem;
  min-height: 1.2rem;
}

.company-card .badges small {
  padding: 0.05rem 0.3rem;
  background: var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  font-size: 0.6rem;
  color: var(--pico-h5-color);
}

.company-card .badges small.highlight {
  background: var(--pico-primary-focus);
}

.company-card .overview {
  margin: 0;
  flex: 1;
  color: var(--pico-muted-color);  /* Use muted color instead of opacity */
  font-size: 0.8rem;
}

.company-card .overview small {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Compact card for map popups */
.company-card.compact {
  height: auto;
}

.company-card.compact article {
  padding: 0.75rem;
  height: auto;
  box-shadow: none;
  margin: 0;
}

/* === Index Page: Directory Header === */
.directory-header {
  align-items: center;
  margin-bottom: var(--pico-spacing);
}

.directory-header .search-group {
  margin: 0;
}

.directory-header input[type="search"] {
  margin: 0;
}

/* Map toggle - checkbox styled as icon button */
.map-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.75rem;
  cursor: pointer;
  background: var(--pico-form-element-background-color);
  border: var(--pico-border-width) solid var(--pico-form-element-border-color);
  border-left: none;
  border-radius: 0 var(--pico-border-radius) var(--pico-border-radius) 0;
}

.map-toggle input { display: none; }
.map-toggle .icon { opacity: 0.5; }
.map-toggle:hover .icon { opacity: 0.75; }

.map-toggle:has(input:checked) {
  background: var(--pico-primary);
  border-color: var(--pico-primary);
}
.map-toggle:has(input:checked) .icon { opacity: 1; color: var(--pico-primary-inverse); }

/* === Index Page: Directory Breadcrumb === */
.directory-breadcrumb ul {
  align-items: center;
}

/* Filter badge with X to clear */
.directory-breadcrumb .filter-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  background: var(--pico-primary-focus);
  border: none;
  border-radius: 1rem;
  cursor: pointer;
  color: inherit;
  margin: 0;
}

.directory-breadcrumb .filter-badge:hover {
  background: var(--pico-primary);
  color: var(--pico-primary-inverse);
}

.directory-breadcrumb .filter-badge svg {
  opacity: 0.7;
}

.directory-breadcrumb .filter-badge:hover svg {
  opacity: 1;
}

.directory-breadcrumb .filter-count {
  font-weight: 600;
}

/* Map iframe */
#map-iframe {
  width: 100%;
  height: calc(100dvh - 180px);
  min-height: 400px;
  border: none;
  border-radius: var(--pico-border-radius);
}

#map-iframe.hidden {
  display: none;
}

/* === Company Page === */
.company-page .info-column {
  background: var(--pico-card-sectioning-background-color);
  border-radius: var(--pico-border-radius);
  padding: var(--pico-spacing);
}

/* Company Logo in Sidebar */
.company-page .company-logo {
  text-align: center;
}

.company-page .company-logo img {
  max-height: 100px;
  max-width: 100%;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

/* Company Badges Inline (below h1) */
.company-page .company-badges-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: -0.5rem 0 1rem 0;
}

.company-page .company-badges-inline .badge-link {
  text-decoration: none;
}

.company-page .company-badges-inline small {
  padding: 0.15rem 0.5rem;
  background: var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  font-size: 0.75rem;
  transition: all 0.15s ease;
}

.company-page .company-badges-inline .badge-link:hover small {
  background: var(--pico-primary);
  color: var(--pico-primary-inverse);
}

/* Content Column */
.company-page .content-column h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: calc(var(--pico-spacing) * 1.5);
  margin-bottom: calc(var(--pico-spacing) * 0.75);
  padding-bottom: calc(var(--pico-spacing) * 0.5);
  border-bottom: 1px solid var(--pico-muted-border-color);
}

.company-page .content-column h2:first-child {
  margin-top: 0;
}

/* Info Column (Sidebar) */
.company-page .contact-person {
  text-align: center;
  padding-bottom: var(--pico-spacing);
  border-bottom: 1px solid var(--pico-muted-color);
}

.company-page .contact-person .contact-name {
  font-weight: 600;
  margin: 0;
}

.company-page .contact-person .contact-title {
  font-size: 0.875rem;
  opacity: 0.7;
  margin: 0.25rem 0 0 0;
}

.company-page .contact-info p {
  margin: 0 0 0.5rem 0;
}

.company-page .contact-info p:last-child {
  margin-bottom: 0;
}

.company-page .contact-info .address {
  font-size: 0.9rem;
  line-height: 1.4;
  word-break: break-word;
}

/* Minimap */
.company-page .minimap {
  border-radius: var(--pico-border-radius);
  overflow: hidden;
}

.company-page .minimap a {
  display: block;
}

.company-page .minimap img {
  width: 100%;
  height: auto;
  display: block;
  transition: filter 0.15s;
}

.company-page .minimap:hover img {
  filter: brightness(0.9);
}

/* Taxonomy icons (Capability Streams and Ownership) - unified styling */
.company-page .taxonomy-section .stream-icons,
.company-page .taxonomy-section .ownership-icons {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.company-page .taxonomy-section .stream-icons a,
.company-page .taxonomy-section .ownership-icons a {
  display: block;
  padding: 0;
}

.company-page .taxonomy-section .stream-icons img,
.company-page .taxonomy-section .ownership-icons img {
  width: 48px;
  height: 48px;
  border-radius: var(--pico-border-radius);
  object-fit: cover;
  transition: all 0.15s ease;
  border: 2px solid transparent;
}

.company-page .taxonomy-section .stream-icons a:hover img,
.company-page .taxonomy-section .ownership-icons a:hover img {
  border-color: var(--pico-primary);
}

/* Taxonomy row layout (streams + ownerships side by side) */
.company-page .taxonomy-section .taxonomy-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.company-page .taxonomy-section .taxonomy-row .taxonomy-column {
  flex: 1;
}

.company-page .taxonomy-section .taxonomy-row .taxonomy-column:first-child {
  flex: 2;
}

.company-page .taxonomy-section ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.company-page .taxonomy-section li {
  margin: 0;
  padding: 0;
}

.company-page .taxonomy-section a {
  display: block;
  padding: calc(var(--pico-spacing) * 0.25) 0;
  text-decoration: none;
}

/* Company Footer with Edit Link */
.company-page .company-footer {
  margin-top: calc(var(--pico-spacing) * 2);
  padding-top: var(--pico-spacing);
  border-top: 1px solid var(--pico-muted-border-color);
  text-align: right;
}

.company-page .company-footer a {
  font-size: 0.85rem;
  color: var(--pico-muted-color);
}

/* === Responsive: Medium screens (768px - 1023px) === */
@media (max-width: 1023px) {
  .company-page .info-column {
    order: -1;
  }
}

/* === Responsive: Small screens (<768px) === */
@media (max-width: 767px) {
  nav .logo {
    height: 40px;
  }

  nav .desktop-only {
    display: none;
  }

  /* Prevent iOS zoom on input focus */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="search"],
  input[type="url"],
  textarea,
  select {
    font-size: 16px;
  }

  /* Filters sidebar becomes slide-out panel */
  .filters-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 85%;
    max-width: 320px;
    height: 100%;
    max-height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    padding-top: 3rem;
  }

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

  .mobile-filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: var(--pico-spacing);
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    width: 100%;
    justify-content: center;
    grid-column: 1 / -1;
  }

  .mobile-filter-toggle .icon {
    flex-shrink: 0;
  }

  .mobile-filter-close {
    display: flex;
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: transparent;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    z-index: 1;
  }

  .mobile-filter-close:hover {
    background: var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
  }

  .mobile-filter-backdrop.open {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
  }

  #map-iframe {
    height: calc(100dvh - 220px);
    min-height: 300px;
  }
}

/* Larger touch targets on touch devices */
@media (pointer: coarse) {
  .filter-item {
    padding: 0.5rem 0.6rem;
    min-height: 44px;
  }

  .stream-icon img {
    width: 44px;
    height: 44px;
  }
}

/* === Print === */
@media print {
  /* Hide interactive elements */
  nav,
  .filters-sidebar,
  .skip-link,
  .search-row,
  .view-toggle,
  .no-results,
  .company-footer,
  #edit-mode,
  #map-iframe,
  .no-print {
    display: none !important;
  }

  body {
    background: white;
    color: black;
    font-size: 11pt;
  }

  .container-fluid {
    padding: 0 !important;
    max-width: 100% !important;
  }

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

  .company-card article {
    padding: 0.4rem !important;
    border: 1px solid #999 !important;
    box-shadow: none !important;
  }

  .company-card .overview,
  .company-card .badges {
    display: none !important;
  }

  .company-card .logo-area {
    height: 40px !important;
    margin-bottom: 0.25rem !important;
  }

  .company-card .name {
    font-size: 0.75rem !important;
  }

  /* Company detail: single column */
  .company-page .grid {
    display: block !important;
  }

  .company-page .info-column {
    margin-bottom: 1rem;
  }

  .company-page .minimap,
  .company-page .stream-icons {
    display: none !important;
  }

  article,
  .company-page .info-column {
    break-inside: avoid;
  }

  h1, h2, h3 {
    break-after: avoid;
  }
}

/* === Reduced Motion (a11y) === */
/* Respect user preferences for reduced motion */
@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;
  }
}

/* === Submit Page === */
.submit-page .required {
  color: var(--pico-del-color);
}

.submit-page #address-status {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.85rem;
}

.submit-page #address-status.success {
  color: var(--pico-ins-color);
}

.submit-page #address-status.warning {
  color: var(--pico-mark-color);
}

.submit-page #address-status.error {
  color: var(--pico-del-color);
}

/* Submit page header */
.submit-page-header {
  margin-bottom: var(--pico-spacing);
}

/* Form sections */
.submit-page .form-section {
  margin-bottom: 1.5rem;
}

.submit-page .form-section h2 {
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

/* Address row */
.submit-page .address-row {
  display: flex;
  gap: 0.5rem;
}

.submit-page .address-row input {
  flex: 1;
  margin-bottom: 0;
}

.submit-page .address-row button {
  margin-bottom: 0;
  width: auto;
}

/* Actions */
.submit-page .actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: var(--pico-spacing);
}

/* Link dialog */
#link-dialog {
  max-width: 500px;
}

#link-dialog button {
  margin-top: 1rem;
}

/* Logo upload */
.submit-page .logo-upload {
  border: 2px dashed var(--pico-form-element-border-color);
  border-radius: var(--pico-border-radius);
  padding: var(--pico-spacing);
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--pico-spacing);
}

.submit-page .logo-upload:hover {
  border-color: var(--pico-primary);
}

.submit-page .logo-upload.dragover {
  border-color: var(--pico-primary);
  background: var(--pico-primary-focus);
}

.submit-page .upload-placeholder {
  color: var(--pico-muted-color);
}

.submit-page .upload-placeholder i {
  width: 48px;
  height: 48px;
  margin-bottom: 0.5rem;
}

.submit-page .upload-preview {
  position: relative;
  display: inline-block;
}

.submit-page .upload-preview img {
  max-width: 160px;
  max-height: 140px;
  object-fit: contain;
  border-radius: var(--pico-border-radius);
}

.submit-page .remove-logo {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--pico-del-color);
  color: white;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

/* === Squire Editor === */
.submit-page .editor-wrapper {
  border: var(--pico-border-width) solid var(--pico-form-element-border-color);
  border-radius: var(--pico-border-radius);
  overflow: hidden;
}

.submit-page .editor-wrapper:focus-within {
  border-color: var(--pico-primary);
  box-shadow: 0 0 0 var(--pico-outline-width) var(--pico-primary-focus);
}

.submit-page .editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.5rem;
  background: var(--pico-muted-background-color);
  border-bottom: var(--pico-border-width) solid var(--pico-form-element-border-color);
}

.submit-page .editor-toolbar button {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--pico-background-color);
  border: var(--pico-border-width) solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  color: var(--pico-color);
  cursor: pointer;
}

.submit-page .editor-toolbar button:hover {
  background: var(--pico-primary-focus);
  border-color: var(--pico-primary);
  color: var(--pico-primary);
}

.submit-page .editor-toolbar button.active {
  background: var(--pico-primary);
  color: var(--pico-primary-inverse);
  border-color: var(--pico-primary);
}

.submit-page .editor-toolbar button svg {
  width: 1rem;
  height: 1rem;
}

.submit-page .editor-toolbar .sep {
  width: var(--pico-border-width);
  background: var(--pico-muted-border-color);
  margin: 0.25rem 0.375rem;
  align-self: stretch;
}

.submit-page .editor-content {
  min-height: 200px;
  padding: 1rem;
  background: var(--pico-form-element-background-color);
  color: var(--pico-color);
  outline: none;
  overflow-y: auto;
}

.submit-page .editor-content h2 {
  font-size: 1.25rem;
  margin: 0.5em 0;
}

.submit-page .editor-content h3 {
  font-size: 1.1rem;
  margin: 0.5em 0;
}

.submit-page .editor-content p {
  margin: 0 0 0.5em;
}

.submit-page .editor-content ul,
.submit-page .editor-content ol {
  padding-left: 1.5em;
  margin: 0.5em 0;
}

.submit-page .editor-content a {
  color: var(--pico-primary);
}

/* Responsive: small screens */
@media (max-width: 767px) {
  .submit-page .actions {
    flex-direction: column;
  }
  
  .submit-page .actions button {
    width: 100%;
  }
}

