:root {
  --brand-blue: #017cc2;
  --brand-sky: #2ea3f2;
  --text-gray: #666666;
  --text-dark: #2b2b2b;
  --bg: #ffffff;
  --bg-soft: #f4f8fb;
  --border: #e2e8ef;
  --danger: #c0392b;
  --radius: 10px;
  --font-heading: "Josefin Sans", Helvetica, Arial, sans-serif;
  --font-body: "Open Sans", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text-gray);
  background: var(--bg);
  line-height: 1.55;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--text-dark);
  margin: 0 0 0.5em;
}

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

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--brand-blue);
  color: #fff; padding: 10px 16px; z-index: 100;
}
.skip-link:focus { left: 0; }

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 50%; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-family: var(--font-heading); color: var(--text-dark); font-size: 1.05rem; }
.brand-text small { color: var(--brand-blue); font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase; }
.top-nav a { color: var(--text-gray); font-size: 0.9rem; }

/* Banners */
.update-banner, .offline-banner {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 10px 16px; text-align: center; font-size: 0.92rem; flex-wrap: wrap;
}
.update-banner { background: #fff7e0; color: #8a6300; border-bottom: 1px solid #f0dca0; }
.update-banner.success { background: #e6f6ec; color: #1e7a43; border-bottom: 1px solid #b9e4c9; }
.update-banner button {
  background: var(--brand-blue); color: #fff; border: none; border-radius: 20px;
  padding: 6px 16px; cursor: pointer; font-weight: 600;
}
.offline-banner { background: #eef2f5; color: #55606b; border-bottom: 1px solid var(--border); }

/* Hero */
.hero {
  background: linear-gradient(135deg, var(--brand-blue), #014f7a);
  color: #fff;
  padding: 46px 0 40px;
}
.hero-inner { display: flex; align-items: flex-start; gap: 28px; }
.hero-logo {
  flex: 0 0 auto; border-radius: 50%; background: #fff; padding: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}
.hero-text { flex: 1 1 auto; min-width: 0; }
@media (max-width: 640px) {
  .hero-inner { flex-direction: column; align-items: center; text-align: center; }
  .hero-logo { width: 120px; height: 120px; }
}
.hero h1 { color: #fff; font-size: clamp(1.5rem, 3vw, 2.1rem); max-width: 820px; }
.hero p { color: #e4f1fa; max-width: 700px; margin-bottom: 22px; }
.collab-note {
  color: #eaf6ff; background: rgba(255,255,255,0.12); border: 1px dashed rgba(255,255,255,0.4);
  border-radius: 10px; padding: 10px 16px; font-size: 0.85rem; max-width: 700px; margin-top: 14px;
}
.collab-note a { color: #fff; text-decoration: underline; }

.search-box {
  display: flex; gap: 10px; max-width: 700px; background: #fff; padding: 6px;
  border-radius: 40px; box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}
.search-box input {
  flex: 1; border: none; outline: none; padding: 12px 18px; font-size: 1rem;
  border-radius: 30px; font-family: var(--font-body); color: var(--text-dark);
}
.search-box button {
  background: var(--brand-sky); color: #fff; border: none; border-radius: 30px;
  padding: 0 26px; font-weight: 700; cursor: pointer; font-family: var(--font-body);
}
.search-box button:hover { background: var(--brand-blue); }
.search-hint { color: #cfe7f6; font-size: 0.85rem; margin-top: 10px; min-height: 1.2em; }

/* Layout */
.layout {
  display: grid; grid-template-columns: 260px 1fr; gap: 30px; padding-top: 30px; padding-bottom: 60px;
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
}

.sidebar h2 { font-size: 1.05rem; }
.category-list { list-style: none; margin: 0 0 24px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.category-list button {
  width: 100%; text-align: left; background: none; border: none; padding: 9px 12px;
  border-radius: 8px; cursor: pointer; color: var(--text-gray); font-family: var(--font-body); font-size: 0.92rem;
  display: flex; justify-content: space-between; gap: 8px;
}
.category-list button:hover { background: var(--bg-soft); color: var(--text-dark); }
.category-list button.active { background: var(--brand-blue); color: #fff; font-weight: 600; }
.category-list .count { opacity: 0.7; font-size: 0.8rem; }

.cat-parent-toggle {
  width: 100%; text-align: left; background: none; border: none; padding: 9px 12px;
  border-radius: 8px; cursor: pointer; color: var(--text-dark); font-family: var(--font-body);
  font-size: 0.92rem; font-weight: 600; display: flex; justify-content: space-between; gap: 8px;
}
.cat-parent-toggle:hover { background: var(--bg-soft); }
.category-sublist { list-style: none; margin: 2px 0 4px; padding: 0 0 0 14px; display: flex; flex-direction: column; gap: 2px; }
.category-sublist button.cat-child { font-size: 0.85rem; padding: 7px 10px; }
.category-sublist button.cat-empty { opacity: 0.5; }

.offline-box {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px;
}
.offline-box h3 { font-size: 0.95rem; }
.offline-box p { font-size: 0.85rem; margin-top: 0; }
.btn-outline {
  width: 100%; background: #fff; border: 1.5px solid var(--brand-blue); color: var(--brand-blue);
  padding: 9px 10px; border-radius: 8px; font-weight: 700; cursor: pointer; font-family: var(--font-body);
}
.btn-outline:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-outline:not(:disabled):hover { background: var(--brand-blue); color: #fff; }
.download-status { font-size: 0.82rem; margin-top: 8px; min-height: 1.2em; color: var(--brand-blue); }
.downloaded-list { list-style: none; padding: 0; margin: 10px 0 0; font-size: 0.82rem; }
.downloaded-list li { padding: 4px 0; border-top: 1px dashed var(--border); display: flex; justify-content: space-between; gap: 6px; }

/* Results */
.results-meta { font-size: 0.9rem; margin-bottom: 14px; color: var(--text-gray); }
.results { display: flex; flex-direction: column; gap: 16px; }

.reg-card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px;
  background: #fff;
}
.reg-card-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; justify-content: space-between;
}
.reg-shortname {
  font-family: var(--font-heading); font-weight: 700; color: var(--brand-blue); font-size: 1.1rem;
}
.reg-tag {
  display: inline-block; background: var(--bg-soft); color: var(--text-gray); font-size: 0.75rem;
  padding: 3px 10px; border-radius: 20px; border: 1px solid var(--border);
}
.reg-title { color: var(--text-dark); font-size: 0.95rem; margin: 4px 0 10px; }
.reg-meta { font-size: 0.8rem; color: #93a0aa; margin-bottom: 10px; }

.article-hit {
  background: var(--bg-soft); border-left: 3px solid var(--brand-sky); border-radius: 6px;
  padding: 10px 14px; margin-top: 8px; font-size: 0.9rem;
}
.article-hit .art-num { font-weight: 700; color: var(--text-dark); }
.article-hit mark { background: #ffe58a; padding: 0 2px; border-radius: 2px; }

.reg-actions { margin-top: 12px; display: flex; gap: 10px; flex-wrap: wrap; }
.btn-primary {
  background: var(--brand-blue); color: #fff !important; border: none; padding: 9px 16px;
  border-radius: 8px; font-weight: 700; cursor: pointer; text-decoration: none !important; font-size: 0.88rem;
}
.btn-primary:hover { background: #015e93; }
.btn-secondary {
  background: none; border: 1.5px solid var(--border); color: var(--text-gray) !important;
  padding: 8px 15px; border-radius: 8px; cursor: pointer; font-size: 0.88rem; text-decoration: none !important;
}
.btn-secondary:hover { border-color: var(--brand-blue); color: var(--brand-blue) !important; }

.derogated-warning {
  background: #fdecea; border: 1px solid #f3b8b0; color: #8a2c20;
  border-radius: 8px; padding: 10px 14px; font-size: 0.85rem; font-weight: 600;
  margin-bottom: 12px;
}
.reg-card-derogated { border-color: #f3b8b0; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-gray); }
.empty-state h3 { color: var(--text-dark); }

/* Modal */
.doc-modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.doc-modal[hidden] { display: none; }
.doc-modal-backdrop { position: absolute; inset: 0; background: rgba(20,30,40,0.55); }
.doc-modal-panel {
  position: relative; background: #fff; max-width: 720px; width: 92%; max-height: 84vh; overflow-y: auto;
  border-radius: 14px; padding: 28px 30px; box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.doc-modal-close {
  position: absolute; top: 14px; right: 14px; background: none; border: none; font-size: 1.1rem;
  cursor: pointer; color: var(--text-gray);
}
.doc-modal-sub { color: var(--brand-blue); font-weight: 600; margin-top: -6px; }
.doc-modal-body { white-space: pre-wrap; font-size: 0.92rem; color: var(--text-dark); border-top: 1px solid var(--border); padding-top: 14px; margin-top: 10px; }
.doc-modal-actions { margin-top: 18px; }

/* Footer */
.site-footer {
  background: var(--brand-blue); color: #dcecf6; padding: 26px 0; margin-top: 20px; font-size: 0.85rem;
}
.footer-inner { display: flex; align-items: center; gap: 18px; }
.footer-inner img { border-radius: 50%; background: #fff; padding: 4px; flex: 0 0 auto; }
.site-footer a { color: #fff; }
.site-footer p { margin: 4px 0; }
.sync-info { opacity: 0.75; font-size: 0.78rem; }
