:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #eef4ff;
    --text: #162033;
    --muted: #64748b;
    --line: #dbe3ef;
    --primary: #1457d9;
    --primary-dark: #0e3e9e;
    --success: #087a55;
    --success-bg: #e7f8f1;
    --shadow: 0 14px 34px rgba(28, 48, 83, 0.09);
    --radius: 16px;
    --container: 1220px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
button, input { font: inherit; }
code { word-break: break-word; }
.container { width: min(var(--container), calc(100% - 36px)); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }

.site-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}
.header-row { min-height: 72px; display: grid; grid-template-columns: auto minmax(260px, 560px) auto; gap: 24px; align-items: center; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 800; letter-spacing: -.02em; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--primary); color: white; font-size: 21px; }
.header-search { display: flex; min-width: 0; }
.header-search input { flex: 1; min-width: 0; border: 1px solid var(--line); border-right: 0; border-radius: 11px 0 0 11px; padding: 10px 13px; background: #f8fafc; color: var(--text); }
.header-search button, .search-form button { border: 0; background: var(--primary); color: white; padding: 10px 16px; border-radius: 0 11px 11px 0; cursor: pointer; font-weight: 700; }
.header-nav { display: flex; align-items: center; gap: 18px; font-weight: 700; white-space: nowrap; }

.site-main { min-height: calc(100vh - 150px); }
.hero { padding: 72px 0 56px; background: radial-gradient(circle at 85% 20%, #d9e8ff 0, transparent 34%), linear-gradient(135deg, #fff 0%, #eef5ff 100%); border-bottom: 1px solid var(--line); }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(340px, .75fr); gap: 56px; align-items: center; }
.eyebrow { margin: 0 0 8px; color: var(--primary); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3 { line-height: 1.15; letter-spacing: -.025em; }
h1 { margin: 0 0 16px; font-size: clamp(2.25rem, 5vw, 4.6rem); }
h2 { margin: 0; font-size: clamp(1.45rem, 2.5vw, 2rem); }
h3 { margin: 0; }
.lead { max-width: 760px; margin: 0; color: #475569; font-size: 1.1rem; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-top: 30px; }
.stats-grid.compact { grid-template-columns: repeat(2, minmax(0,1fr)); margin-top: 0; }
.stat { background: rgba(255,255,255,.88); border: 1px solid var(--line); border-radius: var(--radius); padding: 19px; box-shadow: 0 8px 24px rgba(28,48,83,.05); }
.stat strong { display: block; font-size: 1.55rem; }
.stat span { display: block; color: var(--muted); font-size: .9rem; }

.section { padding-top: 48px; padding-bottom: 64px; }
.section-block { margin-top: 40px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.country-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 18px; }
.country-card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; color: var(--text); box-shadow: 0 5px 18px rgba(28,48,83,.04); transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.country-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: #aac5f8; color: var(--text); }
.country-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.country-code { display: inline-flex; border-radius: 999px; background: var(--surface-soft); color: var(--primary); padding: 4px 9px; font-size: .78rem; font-weight: 800; }
.arrow { font-size: 1.2rem; color: var(--primary); }
.country-card h3 { font-size: 1.25rem; margin-bottom: 18px; }
.country-card dl { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 0; }
.country-card dl div { min-width: 0; }
.country-card dt { color: var(--muted); font-size: .72rem; }
.country-card dd { margin: 2px 0 0; font-weight: 800; }

.page-hero { padding: 42px 0 34px; background: var(--surface); border-bottom: 1px solid var(--line); }
.small-hero { padding-bottom: 28px; }
.entity-hero { background: linear-gradient(180deg, #fff, #f6f9fe); }
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 25px; color: var(--muted); font-size: .88rem; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--primary); }
.page-title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; }
.page-title-row h1 { font-size: clamp(2.2rem, 5vw, 4rem); margin-bottom: 10px; }
.native-name { margin: -3px 0 0; color: var(--muted); font-size: 1.15rem; }
.button { display: inline-flex; justify-content: center; align-items: center; min-height: 44px; padding: 10px 16px; border-radius: 11px; background: var(--primary); color: white; font-weight: 800; border: 1px solid var(--primary); }
.button:hover { background: var(--primary-dark); color: white; }
.button.secondary { background: white; color: var(--primary); border-color: #b8c9e9; }
.button.secondary:hover { border-color: var(--primary); background: var(--surface-soft); }
.badge-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 13px; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; background: var(--surface-soft); color: var(--primary); font-size: .75rem; font-weight: 800; }
.badge.success { background: var(--success-bg); color: var(--success); }
.muted-badge { background: #eef1f5; color: #4b5563; }

.two-column { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 34px; align-items: start; }
.entity-layout { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 34px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: 0 7px 24px rgba(28,48,83,.04); }
.sticky-panel { position: sticky; top: 94px; }
.panel h2 { font-size: 1.2rem; margin-bottom: 18px; }
.panel h3 { margin: 24px 0 10px; font-size: 1rem; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.panel-heading h2 { margin: 0; }
.map-panel { padding: 14px; }
.map { height: 520px; border-radius: 12px; overflow: hidden; background: #e8edf5; }

.entity-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.entity-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 15px 18px; color: var(--text); border-bottom: 1px solid var(--line); transition: background .15s ease; }
.entity-row:last-child { border-bottom: 0; }
.entity-row:hover { background: #f8fbff; color: var(--text); }
.entity-main { min-width: 0; }
.entity-main strong { display: block; overflow-wrap: anywhere; }
.entity-main span { display: block; color: var(--muted); font-size: .87rem; margin-top: 2px; }
.entity-meta { display: flex; align-items: center; justify-content: flex-end; gap: 12px; color: var(--muted); font-size: .82rem; text-align: right; }
.kind-list { display: grid; gap: 2px; }
.kind-list a { display: flex; justify-content: space-between; gap: 16px; padding: 10px 4px; border-bottom: 1px solid var(--line); color: var(--text); }
.kind-list a:last-child { border-bottom: 0; }
.kind-list strong { color: var(--primary); }

.details-list, .translation-list { margin: 0; }
.details-list > div, .translation-list > div { display: grid; grid-template-columns: minmax(110px,.9fr) minmax(0,1.1fr); gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.details-list > div:last-child, .translation-list > div:last-child { border-bottom: 0; }
.details-list dt, .translation-list dt { color: var(--muted); font-size: .84rem; }
.details-list dd, .translation-list dd { margin: 0; text-align: right; font-weight: 650; overflow-wrap: anywhere; }
.details-list small { color: var(--muted); }
.relation-list { display: grid; gap: 8px; }
.relation-list a { display: flex; justify-content: space-between; gap: 12px; padding: 9px 11px; background: #f8fafc; border-radius: 9px; color: var(--text); }
.relation-list small { color: var(--muted); }

.search-form { margin-top: 22px; display: grid; grid-template-columns: minmax(220px, 1fr) 90px 160px auto; max-width: 900px; }
.search-form input { min-width: 0; border: 1px solid var(--line); border-right: 0; padding: 11px 12px; background: white; }
.search-form input:first-child { border-radius: 11px 0 0 11px; }
.search-form button { border-radius: 0 11px 11px 0; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-top: 22px; padding: 14px 18px; background: white; border: 1px solid var(--line); border-radius: 12px; }
.empty-state { padding: 30px; background: white; border: 1px dashed #b9c5d7; border-radius: var(--radius); color: var(--muted); text-align: center; }

.error-page { padding-top: 90px; padding-bottom: 100px; text-align: center; }
.error-code { margin: 0; color: var(--primary); font-size: 5rem; line-height: 1; font-weight: 900; }
.error-page .lead { margin-inline: auto; margin-bottom: 26px; }
.error-actions { display: flex; justify-content: center; gap: 12px; }
.debug-box { max-width: 900px; margin: 20px auto; padding: 15px; overflow: auto; text-align: left; background: #1f2937; color: #f8fafc; border-radius: 10px; }

.site-footer { border-top: 1px solid var(--line); background: white; color: var(--muted); }
.footer-row { min-height: 74px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }

@media (max-width: 980px) {
    .header-row { grid-template-columns: auto 1fr; }
    .header-search { grid-column: 1 / -1; grid-row: 2; padding-bottom: 12px; }
    .header-nav { justify-self: end; }
    .hero-grid, .two-column, .entity-layout { grid-template-columns: 1fr; }
    .country-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .sticky-panel { position: static; }
    .map { height: 430px; }
}

@media (max-width: 680px) {
    .container { width: min(100% - 22px, var(--container)); }
    .header-row { gap: 12px; }
    .brand span:last-child { display: none; }
    .header-nav { gap: 12px; font-size: .9rem; }
    .hero { padding-top: 48px; }
    .country-grid { grid-template-columns: 1fr; }
    .stats-grid, .stats-grid.compact { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .page-title-row { align-items: flex-start; flex-direction: column; }
    .page-title-row .button { width: 100%; }
    .entity-row { align-items: flex-start; }
    .entity-meta { flex-direction: column; align-items: flex-end; gap: 5px; }
    .search-form { grid-template-columns: 1fr 72px; gap: 8px; }
    .search-form input { border: 1px solid var(--line); border-radius: 9px !important; }
    .search-form button { border-radius: 9px; }
    .search-form input[name="kind"] { grid-column: 1 / -1; }
    .map { height: 340px; }
    .footer-row { flex-direction: column; justify-content: center; padding: 16px 0; }
}
