/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:    #2563eb;
  --brand-dk: #1d4ed8;
  --bg:       #f8fafc;
  --bg-alt:   #f1f5f9;
  --surface:  #ffffff;
  --border:   #e2e8f0;
  --text:     #0f172a;
  --muted:    #64748b;
  --code-bg:  #0f172a;
  --code-fg:  #e2e8f0;
  --green:    #16a34a;
  --amber:    #b45309;
  --red:      #dc2626;
  --purple:   #7c3aed;
  --radius:   8px;
  --shadow:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:0 4px 12px rgba(0,0,0,.10);
}

html { scroll-behavior: smooth; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
.pub-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.pub-header-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
}
.pub-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17px; color: var(--brand);
}
.pub-brand svg { width: 22px; height: 22px; }
.pub-nav { display: flex; align-items: center; gap: 20px; }
.pub-nav a { color: var(--muted); font-size: 14px; font-weight: 500; }
.pub-nav a:hover { color: var(--text); text-decoration: none; }
.btn-signin {
  padding: 6px 16px;
  background: var(--brand);
  color: #fff !important;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  transition: background .15s;
}
.btn-signin:hover { background: var(--brand-dk) !important; text-decoration: none !important; }

/* ── Hero ────────────────────────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #3b82f6 100%);
  color: #fff;
  padding: 80px 24px;
}
.hero-inner { max-width: 900px; margin: 0 auto; text-align: center; }
.hero h1 { font-size: clamp(28px, 5vw, 48px); font-weight: 800; line-height: 1.2; }
.hero-sub { margin-top: 16px; font-size: 17px; opacity: .85; max-width: 620px; margin-left: auto; margin-right: auto; }

.hero-stats {
  display: flex; justify-content: center; gap: 48px;
  margin: 40px 0 36px;
}
.hero-stat { text-align: center; }
.hero-stat-val { display: block; font-size: 42px; font-weight: 800; line-height: 1; }
.hero-stat-lbl { display: block; font-size: 13px; opacity: .75; margin-top: 4px; text-transform: uppercase; letter-spacing: .05em; }

.hero-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.btn-hero-primary {
  padding: 12px 28px; background: #fff; color: var(--brand);
  border-radius: var(--radius); font-weight: 700; font-size: 15px;
  transition: transform .15s;
}
.btn-hero-primary:hover { transform: translateY(-1px); text-decoration: none; }
.btn-hero-secondary {
  padding: 12px 28px; background: rgba(255,255,255,.15); color: #fff;
  border: 2px solid rgba(255,255,255,.4); border-radius: var(--radius);
  font-weight: 600; font-size: 15px; transition: background .15s;
}
.btn-hero-secondary:hover { background: rgba(255,255,255,.25); text-decoration: none; }

/* ── Sections ────────────────────────────────────────────────────────────────── */
.section { padding: 72px 24px; }
.section-alt { background: var(--bg-alt); }
.section-inner { max-width: 1200px; margin: 0 auto; }
.section-title { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.section-sub { color: var(--muted); margin-bottom: 40px; }

/* ── Country headings ────────────────────────────────────────────────────────── */
.country-heading {
  grid-column: 1 / -1;
  display: flex; align-items: baseline; gap: 12px;
  padding: 8px 0 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 4px;
}
.country-heading-name {
  font-size: 20px; font-weight: 700; color: var(--text);
}
.country-heading-name.country-unassigned { color: var(--muted); font-style: italic; }
.country-heading-count { font-size: 13px; color: var(--muted); }

/* ── Municipality grid ───────────────────────────────────────────────────────── */
.muni-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 24px;
}
.muni-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: box-shadow .2s, transform .2s;
}
.muni-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.muni-card-header {
  padding: 18px 20px 0;
}
.muni-card-header h3 { font-size: 18px; font-weight: 700; color: var(--text); }

.muni-map-preview {
  height: 180px; margin: 12px 0;
  background: #dde6f0;
  overflow: hidden;
}
.muni-map-preview .ol-viewport { border-radius: 0; }

.muni-card-body { padding: 0 20px 20px; flex: 1; display: flex; flex-direction: column; gap: 14px; }

.muni-stats { display: flex; gap: 24px; }
.muni-stat { text-align: center; flex: 1; }
.stat-val { display: block; font-size: 24px; font-weight: 700; color: var(--brand); }
.stat-lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.layer-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.layer-badge {
  display: inline-block; padding: 2px 10px;
  border-radius: 12px; font-size: 12px; font-weight: 500;
  background: #e0e7ff; color: #3730a3;
}
.layer-badge.geom-polygon   { background: #dcfce7; color: #166534; }
.layer-badge.geom-multipolygon { background: #dcfce7; color: #166534; }
.layer-badge.geom-linestring { background: #fef3c7; color: #92400e; }
.layer-badge.geom-multilinestring { background: #fef3c7; color: #92400e; }
.layer-badge.geom-point     { background: #fee2e2; color: #991b1b; }
.layer-badge.geom-multipoint { background: #fee2e2; color: #991b1b; }

.wmts-url { font-size: 12px; }
.wmts-label { display: block; color: var(--muted); margin-bottom: 3px; font-weight: 500; }
.wmts-endpoint { font-size: 11px; word-break: break-all; background: var(--bg-alt); padding: 4px 8px; border-radius: 4px; display: block; }

.btn-try-lookup {
  margin-top: auto;
  align-self: flex-start;
  padding: 7px 16px;
  background: var(--brand);
  color: #fff; border: none; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.btn-try-lookup:hover { background: var(--brand-dk); }

.loading-msg, .empty-msg { color: var(--muted); padding: 32px 0; text-align: center; font-size: 15px; }

/* ── API docs ────────────────────────────────────────────────────────────────── */
.api-group { margin-bottom: 48px; }
.api-group-title {
  font-size: 20px; font-weight: 700;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
}
.api-group-note { color: var(--muted); margin-bottom: 20px; font-size: 14px; }

.badge {
  display: inline-block; padding: 2px 10px;
  border-radius: 12px; font-size: 12px; font-weight: 600;
}
.badge-open    { background: #dcfce7; color: #166534; }
.badge-auth    { background: #fef3c7; color: #92400e; }
.badge-featured{ background: #ede9fe; color: #5b21b6; font-size: 11px; }

.endpoint-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 16px;
  overflow: hidden;
}
.endpoint-featured { border-color: #a5b4fc; box-shadow: 0 0 0 3px #ede9fe; }

.endpoint-header {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 14px 20px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}
.endpoint-header code { font-size: 13px; color: var(--text); font-weight: 600; }
.endpoint-desc { color: var(--muted); font-size: 13px; }

.method {
  display: inline-block; padding: 2px 10px;
  border-radius: 4px; font-size: 12px; font-weight: 700;
  font-family: monospace; letter-spacing: .03em;
}
.method.get  { background: #dbeafe; color: #1e40af; }
.method.post { background: #dcfce7; color: #166534; }
.method.put  { background: #fef3c7; color: #92400e; }
.method.patch{ background: #e0e7ff; color: #3730a3; }
.method.delete { background: #fee2e2; color: #991b1b; }

.endpoint-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.endpoint-body p { font-size: 14px; color: var(--muted); }
.endpoint-body h4 { font-size: 13px; font-weight: 600; margin-bottom: 6px; }

.param-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.param-table th {
  text-align: left; padding: 6px 12px;
  background: var(--bg-alt); color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}
.param-table td {
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.param-table tr:last-child td { border-bottom: none; }
.param-table code { font-size: 12px; background: var(--bg-alt); padding: 1px 5px; border-radius: 3px; }

.code-block-wrap { position: relative; }
.code-block {
  background: var(--code-bg); color: var(--code-fg);
  padding: 16px 44px 16px 16px;
  border-radius: var(--radius);
  font-size: 13px; font-family: "SF Mono", "Fira Code", Consolas, monospace;
  overflow-x: auto; white-space: pre;
  line-height: 1.6;
}
.code-block.mini { font-size: 12px; padding: 12px 44px 12px 12px; }

.copy-btn {
  position: absolute; top: 8px; right: 8px;
  padding: 3px 10px;
  background: rgba(255,255,255,.1); color: #cbd5e1;
  border: 1px solid rgba(255,255,255,.15); border-radius: 4px;
  font-size: 11px; cursor: pointer; transition: background .15s;
}
.copy-btn:hover { background: rgba(255,255,255,.2); }

.inline-code {
  background: var(--bg-alt); padding: 2px 6px;
  border-radius: 4px; font-family: monospace; font-size: 13px;
}

/* ── Write endpoints grid ────────────────────────────────────────────────────── */
.write-endpoints-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.write-endpoint {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.write-endpoint .endpoint-header {
  background: none; border: none; padding: 0;
  font-size: 13px;
}
.write-endpoint p { font-size: 13px; color: var(--muted); }
.write-endpoint .copy-btn { position: static; margin-top: 4px; align-self: flex-end; }

/* ── Live demo ───────────────────────────────────────────────────────────────── */
.demo-layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 32px;
  align-items: start;
}
@media (max-width: 700px) { .demo-layout { grid-template-columns: 1fr; } }

.lookup-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text); }
.form-group select,
.form-group input {
  padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px;
  background: var(--surface); color: var(--text);
  transition: border-color .15s;
}
.form-group select:focus,
.form-group input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px #dbeafe; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn-lookup {
  padding: 10px 24px; background: var(--brand); color: #fff;
  border: none; border-radius: var(--radius);
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .15s;
  align-self: flex-start;
}
.btn-lookup:hover { background: var(--brand-dk); }

.curl-preview { margin-top: 16px; }
.curl-label { font-size: 12px; color: var(--muted); font-weight: 600; display: block; margin-bottom: 5px; }

.result-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.result-box {
  background: var(--code-bg); color: var(--code-fg);
  padding: 16px; border-radius: var(--radius);
  font-size: 13px; font-family: monospace;
  white-space: pre-wrap; min-height: 200px;
  border: 2px solid transparent;
  transition: border-color .2s;
}
.result-empty { color: #475569; }
.result-ok    { border-color: #22c55e; }
.result-error { border-color: #ef4444; }

/* ── Footer ──────────────────────────────────────────────────────────────────── */
.pub-footer {
  background: var(--code-bg); color: #94a3b8;
  padding: 24px;
  font-size: 13px;
}
.pub-footer-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.footer-brand { font-weight: 600; color: #cbd5e1; }
.footer-sep { color: #334155; }
.pub-footer a { color: #94a3b8; }
.pub-footer a:hover { color: #e2e8f0; }
.pub-footer code { font-size: 12px; color: #64748b; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .pub-nav a:not(.btn-signin) { display: none; }
  .hero-stats { gap: 24px; }
  .hero-stat-val { font-size: 30px; }
}
