/* Search page — extends main styles */

/* Hero: map 50% + issue tiles 50% on wide screens, stack on narrow; equal column height */
.hero-map-and-issues {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
  align-items: stretch;
}

.hero-map {
  flex: 1 1 50%;
  min-width: 280px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.hero-issues {
  flex: 1 1 50%;
  min-width: 280px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

@media (min-width: 640px) {
  .hero-map-and-issues {
    flex-wrap: nowrap;
  }
  .hero-map,
  .hero-issues {
    flex: 0 0 calc(50% - 0.625rem); /* half minus half of gap */
    max-width: calc(50% - 0.625rem);
  }
}

.issue-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
  gap: 0.5rem;
}

.issue-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.5rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  font-size: 0.7rem;
  line-height: 1.2;
  text-align: center;
  min-height: 3rem;
  word-break: break-word;
  white-space: normal;
}

.issue-tile:hover {
  border-color: var(--accent);
  background: rgba(166, 124, 0, 0.06);
}

.issue-tile.selected {
  border-color: var(--accent);
  background: rgba(166, 124, 0, 0.12);
  font-weight: 600;
}

.issue-tile .issue-tile-symbol {
  font-size: 1.25rem;
  line-height: 1;
}

/* Country map: box matches column height; map contents centered, not stretched */
.country-map-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}

.country-map-inner {
  position: relative;
  width: 100%;
  max-width: 100%;
}

.country-map-inner svg {
  display: block;
  width: 100%;
  height: auto;
}

.country-map-inner svg path {
  fill: rgba(0, 0, 0, 0.06);
  stroke: rgba(0, 0, 0, 0.12);
  stroke-width: 0.5;
  cursor: default;
  transition: fill 0.15s ease;
}

.country-map-inner svg path.in-sample {
  cursor: pointer;
  fill: rgba(0, 0, 0, 0.08);
}

.country-map-inner svg path.in-sample:hover,
.country-map-inner svg path.in-sample.hover {
  fill: rgba(166, 124, 0, 0.2);
}

.country-map-inner svg path.in-sample.selected {
  fill: rgba(166, 124, 0, 0.35);
  stroke: rgba(166, 124, 0, 0.5);
}

.country-map-inner svg path.out-of-sample {
  fill: rgba(0, 0, 0, 0.04);
  stroke: rgba(0, 0, 0, 0.06);
}

.country-map-tooltip {
  position: fixed;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  background: var(--text);
  color: var(--bg);
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 10;
  white-space: nowrap;
}

.country-map-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.search-main {
  max-width: 72rem;
  margin: 0 auto;
  padding: 2.5rem 2rem 3rem;
}

.search-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 1rem;
}

.search-sub {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0 0 1rem;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}

.search-form input[type="search"] {
  flex: 1;
  min-width: 12rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 1rem;
}

.search-form input[type="date"] {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
}

.search-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-form select {
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
  min-width: 8rem;
}

.search-form button {
  padding: 0.6rem 1.2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.search-form button:hover {
  opacity: 0.9;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
}

.toolbar-left {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.toolbar-left label {
  font-size: 0.9rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.toolbar-left select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.9rem;
}

.optional-cols {
  margin-left: 0.5rem;
}

.api-status {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.api-status.error {
  color: #c00;
}

.results-summary {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0 0 1rem;
}

.table-wrap {
  overflow-x: auto;
  margin-bottom: 1rem;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  table-layout: fixed;
}

.results-table th:nth-child(1),
.results-table td:nth-child(1) { width: 10%; }   /* Country */
.results-table th:nth-child(2),
.results-table td:nth-child(2) { width: 8%; }    /* Date */
.results-table th:nth-child(3),
.results-table td:nth-child(3) { width: 10%; }   /* Party */
.results-table th:nth-child(4),
.results-table td:nth-child(4) {
  width: 12%;
  max-width: 12%;
  min-width: 0;
  overflow: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
}
.results-table th:nth-child(5),
.results-table td:nth-child(5) {
  width: 42%;
  min-width: 0;
}   /* Title */
.results-table th:nth-child(6),
.results-table td:nth-child(6) { width: 8%; }    /* Show text */
.results-table th.opt-col,
.results-table td.opt-col { width: 8%; }

.results-table th,
.results-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.results-table th {
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.results-table td {
  vertical-align: top;
}

.results-table .title-cell {
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results-table .title-cell a {
  color: var(--text);
  text-decoration: none;
}

.results-table .title-cell a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.results-table .title-cell .title-link {
  display: inline-block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results-table .title-cell .title-link {
  cursor: pointer;
}

/* Country and party links: style like titles (neutral, underline on hover) */
.results-table td:nth-child(1) a,
.results-table td:nth-child(3) a {
  color: var(--text);
  text-decoration: none;
}

.results-table td:nth-child(1) a:hover,
.results-table td:nth-child(3) a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.results-table .title-cell mark {
  background: rgba(166, 124, 0, 0.25);
  padding: 0 0.1em;
}

.results-table .expand-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  background: transparent;
  border: 1px solid var(--muted);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  color: var(--muted);
}

.results-table .expand-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.results-table .search-snippet {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.results-table .search-snippet mark {
  background: rgba(166, 124, 0, 0.25);
  padding: 0 0.1em;
}

.results-table th.opt-col,
.results-table td.opt-col {
  display: none;
}

.results-table th.opt-col.visible,
.results-table td.opt-col.visible {
  display: table-cell;
}

.pagination {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.pagination button {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
}

.pagination button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination .page-info {
  font-size: 0.9rem;
  color: var(--muted);
  margin-left: 0.5rem;
}

/* Responsive tweaks for narrow screens */
@media (max-width: 700px) {
  .results-table {
    table-layout: auto;
  }

  /* Stack title and button on their own line to avoid overlap */
  .results-table td:nth-child(5),
  .results-table td:nth-child(6) {
    display: block;
    width: 100%;
  }

  .results-table td:nth-child(6) {
    padding-top: 0;
  }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--bg);
  padding: 1.5rem;
  border-radius: 8px;
  max-width: 28rem;
  width: 90%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-content h3 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.modal-content p {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.download-cols {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.download-cols label {
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Text overlay */
.text-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 101;
  padding: 2rem;
}

.text-overlay[hidden] {
  display: none;
}

.text-overlay-content {
  background: var(--bg);
  max-width: 40rem;
  max-height: 80vh;
  overflow: auto;
  padding: 1.5rem;
  border-radius: 8px;
  position: relative;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

#text-overlay-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}

#text-overlay-close:hover {
  color: var(--text);
}

.text-overlay-content h4 {
  margin: 0 2rem 0.5rem 0;
  font-size: 1.1rem;
}

.text-overlay-content #text-overlay-meta {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.text-overlay-body {
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.sent-codes {
  margin: -0.35rem 0 0.85rem;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted);
}

.sent-codes.is-loading {
  font-style: italic;
  color: var(--accent);
}

.text-overlay-body .sent {
  position: relative;
  margin: 0 0 0.75rem;
  white-space: normal;
}

.sent-label {
  position: absolute;
  left: 0;
  bottom: calc(100% - 0.15rem);
  z-index: 2;
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.sent:hover .sent-label,
.sent:focus-within .sent-label {
  opacity: 1;
}

