:root {
  --bg: #eef7f1;
  --bg-soft: #f7fbf4;
  --panel: #fbfdf9;
  --panel-strong: #ffffff;
  --text: #183026;
  --muted: #64756b;
  --accent: #2d8a57;
  --accent-dark: #1f6540;
  --accent-deep: #154a31;
  --accent-soft: #d9efdf;
  --accent-pale: #e8f5e8;
  --accent-row: #dceddf;
  --button-soft-bg: #edf7ef;
  --button-soft-border: #bfdcc7;
  --button-soft-text: #245f3c;
  --action-button-height: 28px;
  --danger: #b44a4a;
  --border: #cfe2d4;
  --shadow: rgba(24, 48, 38, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(181, 221, 190, 0.5), transparent 34rem),
    linear-gradient(135deg, var(--bg), var(--bg-soft));
  color: var(--text);
  min-height: 100vh;
}

.container {
  position: relative;
  width: min(1000px, 92vw);
  margin: 32px auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 16px 38px var(--shadow);
}

.info-button {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid #1f6540;
  background: #2d8a57;
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
  box-shadow: 0 6px 12px rgba(35, 112, 71, 0.22);
}

.info-button:hover {
  background: #1f6540;
}

.modal.info-modal {
  width: min(430px, 92vw);
}

.modal.codes-modal {
  width: min(560px, 94vw);
}

.modal.enrollment-modal {
  width: min(760px, 96vw);
}

.info-modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
  text-align: left;
  padding-top: 16px;
  padding-bottom: 20px;
}

.info-card {
  border: 1px solid #bfdcc7;
  border-radius: 12px;
  background: #f8fcf9;
  padding: 14px 12px;
}

.info-card-license {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.info-line {
  margin: 0;
  color: var(--text);
  font-weight: 600;
}

.info-line-author {
  display: flex;
  align-items: center;
}

.info-label {
  color: var(--text);
  font-weight: 700;
}

.info-value {
  color: #253a30;
  font-weight: 500;
  margin-left: 4px;
}

.github-inline-link {
  display: inline-flex;
  width: 32px;
  height: 32px;
  margin-left: 8px;
  vertical-align: middle;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: #133b26;
  transition: transform 0.16s ease, background-color 0.16s ease;
}

.github-inline-link svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.github-inline-link:hover {
  background: #e6f5eb;
  transform: translateY(-1px);
}

.license-link {
  display: inline-flex;
  flex: 0 0 auto;
}

.license-link img {
  display: block;
  width: 96px;
  height: auto;
}

.info-action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1;
  text-decoration: none;
  box-shadow: 0 6px 12px rgba(35, 112, 71, 0.16);
  transition: background-color 0.16s ease;
}

.info-action-link:hover {
  color: #fff;
  background: var(--accent-dark);
}

.info-action-link:visited,
.info-action-link:active {
  color: #fff;
}

.info-action-link:active {
  transform: translateY(1px);
}

.info-action-link:focus-visible {
  outline: 3px solid rgba(47, 143, 91, 0.26);
  outline-offset: 2px;
}

.codes-table {
  box-shadow: none;
}

.enrollment-description {
  margin: 0 0 10px;
  color: var(--muted);
}

.enrollment-table {
  box-shadow: none;
  table-layout: fixed;
}

.enrollment-table th:first-child {
  width: auto;
}

.enrollment-table th:nth-child(2),
.enrollment-table td:nth-child(2),
.enrollment-table th:nth-child(3),
.enrollment-table td:nth-child(3),
.enrollment-table th:nth-child(4),
.enrollment-table td:nth-child(4) {
  width: 86px;
}

.enrollment-table th,
.enrollment-table td {
  text-align: center;
}

.enrollment-table th:first-child,
.enrollment-table td:first-child {
  color: var(--accent-deep);
  text-align: left;
}

.enrollment-table th:nth-child(2),
.enrollment-table td:nth-child(2),
.enrollment-table th:nth-child(3),
.enrollment-table td:nth-child(3),
.enrollment-table th:last-child,
.enrollment-table td:last-child {
  white-space: nowrap;
}

h1 {
  margin: 0 0 18px;
  padding-bottom: 12px;
  border-bottom: 3px solid var(--accent);
  font-size: 1.6rem;
  letter-spacing: 0;
  color: var(--accent-deep);
}

p {
  margin: 0 0 16px;
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

input {
  width: min(360px, 100%);
  max-width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: inset 0 1px 2px rgba(24, 48, 38, 0.04);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 143, 91, 0.16);
}

input::placeholder {
  color: #8a9b90;
  opacity: 1;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: background-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
  box-shadow: 0 8px 16px rgba(35, 112, 71, 0.16);
}

button:hover {
  background: var(--accent-dark);
}

button:focus-visible {
  outline: 3px solid rgba(47, 143, 91, 0.26);
  outline-offset: 2px;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.7;
  cursor: wait;
  transform: none;
}

.message {
  margin-bottom: 10px;
  min-height: 1.2em;
  color: var(--muted);
}

.message:empty {
  display: none;
}

.message.error {
  color: var(--danger);
}

.meta {
  margin-bottom: 12px;
  font-size: 0.96rem;
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(24, 48, 38, 0.06);
}

th,
td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  width: 38%;
  background: var(--accent-row);
  font-weight: 600;
  color: var(--accent-deep);
}

tr:hover td {
  background: #f6fbf3;
}

tr:hover th {
  background: #d2e8d7;
}

.value-with-copy {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--action-button-height);
  padding: 4px 10px;
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
  border-radius: 6px;
  background: var(--button-soft-bg);
  color: var(--button-soft-text);
  border: 1px solid var(--button-soft-border);
  box-shadow: none;
}

.copy-btn:hover {
  background: #dcefe2;
}

.copy-btn-light {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.copy-btn-light:hover {
  background: var(--accent-dark);
}

.coord-with-map {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.coord-with-map :is(button, .call-btn) {
  min-height: var(--action-button-height);
}

.coord-with-map > span + :is(button, .call-btn) {
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  box-shadow: none;
}

.coord-with-map > span + :is(button, .call-btn):hover {
  background: var(--accent-dark);
}

.coord-with-map > span + :is(button, .call-btn) + :is(button, .call-btn) {
  background: var(--button-soft-bg);
  color: var(--button-soft-text);
  border: 1px solid var(--button-soft-border);
  box-shadow: none;
}

.coord-with-map > span + :is(button, .call-btn) + :is(button, .call-btn):hover {
  background: #dcefe2;
}

.coord-with-map :is(button, .call-btn) + :is(button, .call-btn) {
  margin-left: -2px;
}

.codes-btn,
.map-btn,
.territorial-map-btn,
.comarca-map-btn,
.municipi-map-btn,
.educational-service-map-btn,
.enrollment-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--action-button-height);
  padding: 4px 10px;
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  box-shadow: none;
}

.codes-btn:hover,
.territorial-map-btn:hover,
.comarca-map-btn:hover,
.municipi-map-btn:hover,
.educational-service-map-btn:hover,
.enrollment-btn:hover {
  background: var(--accent-dark);
}

.call-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--action-button-height);
  padding: 4px 10px;
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  box-shadow: none;
  transition: background-color 0.16s ease, transform 0.16s ease;
}

.call-btn:hover {
  color: #fff;
  background: var(--accent-dark);
}

.call-btn:visited,
.call-btn:active {
  color: #fff;
}

.call-btn:active {
  transform: translateY(1px);
}

.phone-copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--action-button-height);
  padding: 4px 10px;
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
  border-radius: 6px;
  background: var(--button-soft-bg);
  color: var(--button-soft-text);
  border: 1px solid var(--button-soft-border);
  box-shadow: none;
}

.phone-copy-btn:hover {
  background: #dcefe2;
}

.web-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--action-button-height);
  padding: 4px 10px;
  font-size: 0.82rem;
  line-height: 1;
  white-space: nowrap;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  box-shadow: none;
}

.web-btn:hover {
  background-color: var(--accent-dark);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 34, 25, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 20;
}

.modal {
  width: min(760px, 96vw);
  max-height: calc(100vh - 28px);
  background: var(--panel-strong);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 18px 42px rgba(14, 34, 25, 0.22);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-pale);
  font-weight: 600;
}

.modal-body {
  padding: 10px 12px 14px;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.modal-map {
  width: 100%;
  height: 440px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

#territorialMap {
  background: #f8fcf9;
}

a {
  color: var(--accent-dark);
  font-weight: 600;
}

a:hover {
  color: #185a36;
}

tr:last-child td,
tr:last-child th {
  border-bottom: 0;
}

.hidden {
  display: none;
}

.match-list {
  margin: 8px 0 0;
  display: grid;
  gap: 6px;
  max-height: 250px;
  overflow: auto;
  padding-right: 4px;
}

.match-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel-strong);
  box-shadow: 0 3px 10px rgba(24, 48, 38, 0.05);
  transition: border-color 0.16s ease, background-color 0.16s ease;
}

.match-row:hover {
  border-color: #aad6b8;
  background: #fbfef9;
}

.match-name {
  font-weight: 700;
  color: #173528;
}

.match-town {
  color: var(--muted);
  font-weight: 500;
}

.match-view-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--action-button-height);
  padding: 4px 10px;
  font-size: 0.84rem;
  line-height: 1;
  white-space: nowrap;
  border-radius: 6px;
  flex: 0 0 auto;
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  box-shadow: none;
}

@media (max-width: 760px) {
  .container {
    margin: 18px auto;
    padding: 16px;
  }

  th,
  td {
    font-size: 0.92rem;
  }
}
