:root {
  --blue: #1559b4;
  --blue-dark: #063b5c;
  --blue-soft: #ddf3ef;
  --blue-border: #cfe5e8;
  --turquoise: #21a6a1;
  --turquoise-dark: #087d78;
  --sky-soft: #eaf6fa;
  --cream: #faf8f2;
  --text: #183448;
  --muted: #536b79;
  --border: #cfe5e8;
  --background: #eaf6fa;
  --white: #ffffff;
  --danger: #b42318;
  --font-brand: "Baloo 2", "Arial Rounded MT Bold", sans-serif;
  --font-heading: "Poppins", "Segoe UI", sans-serif;
  --font-body: "Roboto", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background:
    radial-gradient(circle at 0% 10%, rgba(33, 166, 161, 0.15), transparent 29%),
    radial-gradient(circle at 88% 6%, rgba(7, 90, 140, 0.08), transparent 34%),
    linear-gradient(180deg, var(--sky-soft) 0%, var(--cream) 100%);
  color: var(--text);
}

button,
a {
  font: inherit;
}

.document-kicker,
.document-heading h1,
.print-btn,
.fishing-zone-notice h2,
.section-title,
.map-panel h2 {
  font-family: var(--font-heading);
}

.summary-row strong,
.license-card-header strong,
.license-data strong {
  font-family: var(--font-heading);
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
}

.footer-brand strong {
  font-family: var(--font-brand);
}

[hidden] {
  display: none !important;
}

.page-shell {
  width: 100%;
  min-height: 100vh;
}

.state {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.loader {
  width: 36px;
  height: 36px;
  border: 3px solid #dbe2ff;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.state-error p {
  color: var(--danger);
  font-weight: 700;
}

pre {
  max-width: 680px;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--white);
  color: var(--text);
  text-align: left;
}

.trace-page {
  width: min(1240px, calc(100% - 32px));
  margin: 24px auto;
  padding: 18px;
  border: 1px solid #edf0f5;
  border-radius: 16px;
  background: var(--white);
  box-shadow: 0 18px 45px rgba(6, 59, 92, 0.1);
}

.document-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  grid-template-rows: auto auto;
  gap: 14px 16px;
  margin-bottom: 16px;
}

.topbar {
  display: flex;
  grid-column: 1;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--blue-border);
  border-radius: 12px;
  background:
    radial-gradient(circle at 90% 0%, rgba(33, 166, 161, 0.13), transparent 36%),
    linear-gradient(135deg, #ffffff 0%, #f1fafb 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-icon-link:focus-visible {
  border-radius: 8px;
  outline: 3px solid rgba(33, 166, 161, 0.28);
  outline-offset: 4px;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid var(--blue-border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--white);
}

.brand-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scale(1.65);
}

.document-heading {
  display: grid;
  gap: 2px;
}

.document-kicker {
  color: var(--turquoise-dark);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.document-heading h1 {
  margin: 0;
  color: var(--blue-dark);
  font-size: 21px;
  line-height: 1.2;
}

.document-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.print-btn {
  min-height: 30px;
}

a.print-btn {
  text-decoration: none;
}

.fishing-zone-notice {
  display: grid;
  grid-column: 1;
  grid-template-columns: minmax(220px, 0.38fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(12px, 2vw, 24px);
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--blue-border);
  border-radius: 10px;
  background: var(--blue-soft);
}

.fishing-zone-notice h2 {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--blue-dark);
  font-size: clamp(13px, 1.35vw, 15px);
  line-height: 1.35;
  text-wrap: balance;
}

.fishing-zone-notice p {
  margin: 0;
  color: var(--text);
  font-size: clamp(11px, 1.1vw, 13px);
  line-height: 1.45;
}

.fishing-zone-notice p span {
  display: block;
}

.fishing-zone-notice p span + span {
  margin-top: 3px;
}

@media screen and (max-width: 700px) {
  .fishing-zone-notice {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

.trace-code {
  color: var(--muted);
  font-size: 12px;
}

.trace-code strong {
  color: var(--text);
}

.print-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--turquoise-dark);
  border-radius: 8px;
  padding: 6px 10px;
  background: linear-gradient(135deg, var(--turquoise) 0%, var(--turquoise-dark) 100%);
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 5px 14px rgba(8, 125, 120, 0.22);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.print-btn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.print-btn:hover {
  filter: brightness(0.95);
  box-shadow: 0 7px 18px rgba(8, 125, 120, 0.3);
  transform: translateY(-1px);
}

.print-btn:active {
  box-shadow: 0 3px 8px rgba(8, 125, 120, 0.22);
  transform: translateY(0);
}

.print-btn:focus-visible {
  outline: 3px solid rgba(33, 166, 161, 0.28);
  outline-offset: 3px;
}

.trace-layout {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.trace-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.summary-card,
.license-card,
.map-panel,
.additional-section {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--white);
  box-shadow: 0 6px 18px rgba(16, 24, 40, 0.05);
}

.summary-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 12px;
  overflow: hidden;
  padding-bottom: 8px;
  background: var(--white);
}

.section-title {
  grid-column: 1 / -1;
  margin: 0;
  padding: 14px 15px;
  border-bottom: 1px solid #edf0f5;
  background: var(--sky-soft);
  color: var(--blue-dark);
  font-size: 15px;
}

.summary-row {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  min-height: 82px;
  padding: 14px 16px;
  background: var(--white);
}

.summary-card .summary-row {
  border: 0;
}

#commerce-section {
  display: contents;
}

.summary-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--blue-soft);
  color: var(--turquoise-dark);
}

.summary-icon svg {
  width: 19px;
  height: 19px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.summary-row > div {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.summary-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.license-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 14px;
  row-gap: 8px;
  padding: 15px;
  border-color: var(--blue-border);
}

.license-card .section-title {
  grid-column: 1 / -1;
  margin: -15px -15px 15px;
  border-radius: 9px 9px 0 0;
}

.license-card-header {
  display: flex;
  grid-column: 1 / -1;
  min-height: 54px;
  align-items: center;
  gap: 12px;
}

.fisherman-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--blue-soft);
  color: var(--turquoise-dark) !important;
}

.fisherman-icon svg,
.license-icon-link svg {
  width: 19px;
  height: 19px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.license-card-header > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.license-card-header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
}

.license-data {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 8px 0 2px;
  border: 0;
  font-size: 12px;
}

.license-card .license-data + .license-data {
  padding-left: 0;
  border-left: 0;
}

.license-data > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.license-data span {
  color: var(--muted);
  font-weight: 500;
}

.license-number-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.license-icon-link {
  display: inline-grid;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 7px;
  color: var(--blue);
  transition: background 0.18s ease, color 0.18s ease;
}

.license-icon-link:hover,
.license-icon-link:focus-visible {
  background: var(--blue-border);
  color: #141414;
  outline: none;
}

.header-qr {
  display: grid;
  grid-column: 2;
  grid-row: 1 / 3;
  place-items: center;
  padding: 10px;
  border: 1px solid var(--blue-border);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--white), var(--sky-soft));
}

.qr-code-frame {
  display: grid;
  width: 190px;
  height: 190px;
  place-items: center;
  padding: 7px;
  border: 1px solid var(--blue-border);
  border-radius: 9px;
  background: var(--white);
}

#qr-code {
  display: block;
  width: 174px;
  height: 174px;
}

.map-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  overflow: hidden;
  position: sticky;
  top: 16px;
}

.map-panel h2 {
  margin: 0;
  padding: 15px 18px 12px;
  color: var(--blue-dark);
  font-size: 15px;
  font-weight: 700;
}

.map-card {
  position: relative;
  min-height: 480px;
  overflow: hidden;
  border-width: 1px 0;
  border-radius: 0;
}

#map {
  width: 100%;
  height: 480px;
  background: var(--sky-soft);
}

#print-map-image {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--sky-soft);
}

#map.map-fallback {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, transparent 49%, rgba(33, 166, 161, 0.1) 50%, transparent 51%),
    linear-gradient(transparent 49%, rgba(33, 166, 161, 0.1) 50%, transparent 51%),
    var(--sky-soft);
  background-size: 80px 80px;
  text-align: center;
}

#map.map-fallback div {
  max-width: 330px;
  padding: 18px;
  border: 1px solid var(--blue-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
}

#map.map-fallback strong {
  display: block;
  margin-bottom: 6px;
}

#map.map-fallback span {
  color: var(--muted);
  font-size: 12px;
}

.mapboxgl-ctrl-top-left {
  top: 8px;
  left: 8px;
}

.mapboxgl-ctrl-group {
  border-radius: 4px !important;
  box-shadow: 0 1px 4px rgba(16, 24, 40, 0.18) !important;
}

.mapboxgl-ctrl-group button {
  width: 30px !important;
  height: 30px !important;
}

.additional-section {
  margin-top: 18px;
  padding: 18px;
}

.additional-section h2 {
  margin: 0 0 14px;
  font-size: 15px;
}

.additional-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.additional-grid article {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.additional-grid span {
  color: var(--muted);
  font-size: 11px;
}

.additional-grid strong {
  font-size: 13px;
}

.document-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding: 14px 2px 2px;
  border-top: 1px solid var(--blue-border);
  color: var(--muted);
  font-size: 11px;
}

.footer-brand {
  display: flex;
  align-items: center;
}

.footer-brand > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.footer-brand strong {
  color: var(--blue-dark);
  font-size: 12px;
}

.footer-brand > div span {
  color: var(--muted);
  font-size: 10px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 18px;
}

.footer-links a {
  color: var(--blue-dark);
  font-weight: 600;
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media screen and (max-width: 980px) {
  .trace-layout {
    grid-template-columns: 1fr;
  }

  .map-panel {
    position: static;
  }

  .map-card,
  #map {
    min-height: 420px;
    height: 420px;
  }
}

@media screen and (max-width: 820px) {
  .trace-page {
    width: min(100% - 20px, 680px);
    margin: 10px auto;
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .document-intro {
    grid-template-columns: minmax(0, 1fr) 170px;
    gap: 10px;
  }

  .header-qr {
    padding: 7px;
  }

  .qr-code-frame {
    width: 154px;
    height: 154px;
  }

  #qr-code {
    width: 138px;
    height: 138px;
  }

  .topbar-actions {
    align-items: flex-end;
    flex-direction: column;
    gap: 7px;
  }

  .trace-layout {
    grid-template-columns: 1fr;
  }

  .trace-sidebar {
    grid-template-columns: 1fr;
  }

  .map-card,
  #map {
    min-height: 430px;
    height: 430px;
  }
}

@media screen and (max-width: 520px) {
  .trace-page {
    width: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .brand span,
  .trace-code {
    display: none;
  }

  .document-heading h1 {
    font-size: 17px;
  }

  .document-heading > p:not(.trace-code) {
    font-size: 11px;
  }

  .brand-icon {
    width: 38px;
    height: 38px;
  }

  .print-btn {
    padding: 5px 9px;
  }

  .document-intro {
    grid-template-columns: 1fr;
  }

  .topbar,
  .fishing-zone-notice,
  .header-qr {
    grid-column: 1;
  }

  .header-qr {
    grid-row: auto;
    padding: 10px;
  }

  .fishing-zone-notice {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
  }

  .fishing-zone-notice h2 {
    align-items: flex-start;
    font-size: 13px;
    line-height: 1.3;
  }

  .fishing-zone-notice p {
    overflow-wrap: anywhere;
    font-size: 11px;
    line-height: 1.45;
  }

  .fishing-zone-notice p span + span {
    margin-top: 5px;
  }

  .summary-card {
    display: block;
  }

  .license-card {
    grid-template-columns: 1fr;
  }

  .license-card .license-data + .license-data {
    padding-left: 0;
    border-left: 0;
  }

  .additional-grid {
    grid-template-columns: 1fr;
  }

  .document-footer,
  .footer-links {
    align-items: flex-start;
    flex-direction: column;
  }

  .footer-links {
    gap: 7px;
  }

  .map-card,
  #map {
    min-height: 360px;
    height: 360px;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 6mm;
  }

  html,
  body {
    width: 100%;
    min-height: 0;
    background: var(--white);
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .trace-page {
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .print-btn {
    display: none !important;
  }

  .document-intro {
    grid-template-columns: minmax(0, 1fr) 106px;
    gap: 7px;
    margin-bottom: 7px;
  }

  .topbar {
    margin: 0;
    padding: 7px 10px;
    border-radius: 8px;
  }

  .brand-icon {
    width: 40px;
    height: 40px;
  }

  .document-heading h1 {
    font-size: 17px;
  }

  .document-heading p {
    font-size: 10px;
  }

  .fishing-zone-notice {
    margin: 0;
    padding: 7px 10px;
    border-radius: 8px;
  }

  .fishing-zone-notice h2 {
    margin-bottom: 2px;
    font-size: 12px;
  }

  .fishing-zone-notice p {
    font-size: 9px;
    line-height: 1.35;
  }

  .trace-layout {
    grid-template-columns: minmax(260px, 39%) minmax(0, 1fr);
    gap: 7px;
    break-inside: avoid;
  }

  .trace-sidebar {
    gap: 7px;
  }

  .section-title,
  .map-panel h2 {
    padding: 8px 10px;
    font-size: 11px;
  }

  .summary-row {
    min-height: 60px;
    grid-template-columns: 27px 1fr;
    gap: 8px;
    padding: 8px;
  }

  .summary-icon,
  .fisherman-icon {
    width: 27px;
    height: 27px;
  }

  .summary-icon svg,
  .fisherman-icon svg {
    width: 16px;
    height: 16px;
  }

  .summary-label,
  .license-card-header span,
  .license-data span {
    font-size: 10px;
  }

  .summary-row strong,
  .license-card-header strong,
  .license-data strong {
    font-size: 11px;
  }

  .license-card {
    padding: 9px;
  }

  .license-card .section-title {
    margin: -9px -9px 8px;
  }

  .license-card-header {
    min-height: 34px;
    gap: 8px;
  }

  .license-data {
    margin: 0;
    padding: 4px 0;
    grid-template-columns: 27px 1fr;
    gap: 8px;
  }

  .license-icon-link {
    display: none !important;
  }

  .header-qr {
    padding: 4px;
    border-radius: 8px;
  }

  .qr-code-frame {
    width: 96px;
    height: 96px;
    padding: 4px;
  }

  #qr-code {
    width: 86px;
    height: 86px;
  }

  .map-panel {
    position: static;
    break-inside: avoid;
  }

  .map-card {
    aspect-ratio: 48 / 35;
    height: auto;
    min-height: 0;
  }

  #map {
    height: 100%;
  }

  #map:has(+ #print-map-image[src]) {
    display: none;
  }

  .map-card.print-map-ready #map {
    display: none;
  }

  #print-map-image[src] {
    display: block;
    width: 100%;
    height: 100%;
  }

  .map-card.print-map-ready #print-map-image {
    display: block;
    width: 100%;
    height: 100%;
  }

  .document-footer {
    margin-top: 7px;
    padding: 7px 0 0;
    break-inside: avoid;
  }

  .footer-brand strong {
    font-size: 10px;
  }

  .footer-brand > div span {
    font-size: 8px;
  }

  .footer-links a {
    padding: 0;
    font-size: 8px;
  }
}
