/*
  Royal Archive
  Institutional reference-library styling: a framed white page on a grey ground, a navy
  navigation bar with section menus, serif headings, a plain sans body, thin rules, and dense
  tables. Fonts are self-hosted: Source Serif 4 (headings and reading text), IBM Plex Sans (body
  and controls), IBM Plex Mono (citations).
*/

@font-face {
  font-family: "Source Serif 4";
  src: url("../assets/fonts/source-serif-4-latin.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Source Serif 4";
  src: url("../assets/fonts/source-serif-4-latin-italic.woff2") format("woff2");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Sans";
  src: url("../assets/fonts/plex-sans-latin.woff2") format("woff2");
  font-weight: 100 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("../assets/fonts/plex-mono-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("../assets/fonts/plex-mono-latin-500.woff2") format("woff2");
  font-weight: 500 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ground: #e4e7ea;
  --page: #ffffff;
  --panel: #f4f5f6;
  --panel-strong: #e9ecef;
  --media: #f7f7f6;
  --text: #222426;
  --text-secondary: #5b6167;
  --border: #c9ced3;
  --border-light: #e1e4e7;
  --navy: #1c3557;
  --navy-dark: #12243d;
  --navy-text: #ffffff;
  --link: #1d4f8c;
  --link-hover: #0f3361;
  --accent: #7d2430;
  --selected: #e8eef6;
  --focus: #f2b632;
  --overlay: rgba(20, 24, 28, 0.65);
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --width: 1240px;
  --gutter: clamp(16px, 2.5vw, 28px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground: #101215;
    --page: #1a1d21;
    --panel: #22262b;
    --panel-strong: #2b3036;
    --media: #23272c;
    --text: #e3e6e9;
    --text-secondary: #a3abb3;
    --border: #3e454d;
    --border-light: #2f353b;
    --navy: #16263b;
    --navy-dark: #0e1a2a;
    --link: #8cb8ea;
    --link-hover: #b9d4f3;
    --accent: #e0909a;
    --selected: #24344a;
    --overlay: rgba(0, 0, 0, 0.75);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #101215;
  --page: #1a1d21;
  --panel: #22262b;
  --panel-strong: #2b3036;
  --media: #23272c;
  --text: #e3e6e9;
  --text-secondary: #a3abb3;
  --border: #3e454d;
  --border-light: #2f353b;
  --navy: #16263b;
  --navy-dark: #0e1a2a;
  --link: #8cb8ea;
  --link-hover: #b9d4f3;
  --accent: #e0909a;
  --selected: #24344a;
  --overlay: rgba(0, 0, 0, 0.75);
}

/* ----- Base ----- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.9375rem;
  line-height: 1.55;
}

body.scroll-locked {
  overflow: hidden;
}

/* The framed page. */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: calc(var(--width) + 2px);
  margin: 0 auto;
  border-right: 1px solid var(--border);
  border-left: 1px solid var(--border);
  background: var(--page);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.08);
}

img {
  max-width: 100%;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 0.5rem;
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
}

p {
  margin: 0 0 1rem;
}

a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--link-hover);
}

button,
input,
select {
  font-family: var(--sans);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.wrap {
  width: 100%;
  padding: 0 var(--gutter);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.5rem 1rem;
  background: var(--focus);
  color: #111;
}

.skip-link:focus {
  left: 0;
}

.t-mono {
  font-family: var(--mono);
}

.secondary,
.t-soft {
  color: var(--text-secondary);
}

/* An icon from assets/glyphs, drawn in the current text colour. */
.glyph {
  display: inline-block;
  flex: none;
  width: 1.1em;
  height: 1.1em;
  background: currentColor;
  -webkit-mask: var(--glyph) center / contain no-repeat;
  mask: var(--glyph) center / contain no-repeat;
  vertical-align: -0.16em;
}

/* ----- Masthead and navigation bar ----- */

.masthead-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-top: 1.1rem;
  padding-bottom: 1rem;
}

.brand {
  display: flex;
  flex-direction: column;
  margin-right: auto;
  color: var(--text);
  text-decoration: none;
}

.brand:hover {
  color: var(--text);
}

.brand-text {
  font-family: var(--serif);
  font-size: 1.875rem;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0.005em;
}

.brand-sub {
  color: var(--text-secondary);
  font-family: var(--serif);
  font-size: 0.9375rem;
  font-style: italic;
}

.masthead-actions {
  display: flex;
  gap: 0.5rem;
}

.mast-btn {
  min-height: 32px;
  padding: 0.2rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.8125rem;
  cursor: pointer;
}

.mast-btn:hover {
  border-color: var(--text-secondary);
}

.menu-btn {
  display: none;
}

.site-nav {
  border-top: 3px solid var(--accent);
  background: var(--navy);
}

.site-nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-list {
  display: flex;
  flex-wrap: wrap;
}

.nav-item {
  position: relative;
}

.nav-top {
  display: block;
  padding: 0.7rem 1rem;
  font-family: var(--sans);
  line-height: 1.5;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  background: none;
  color: var(--navy-text);
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

.nav-top:hover,
.nav-toggle[aria-expanded="true"] {
  background: var(--navy-dark);
  color: var(--navy-text);
  text-decoration: underline;
}

.nav-top[aria-current="page"],
.nav-item.is-current > .nav-top {
  box-shadow: inset 0 -3px 0 var(--focus);
}

.nav-toggle::after {
  content: "";
  display: inline-block;
  width: 0.4em;
  height: 0.4em;
  margin-left: 0.5em;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-0.2em) rotate(45deg);
}

.nav-toggle[aria-expanded="true"]::after {
  transform: translateY(0.05em) rotate(-135deg);
}

.nav-menu {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 40;
  min-width: 330px;
  padding: 0.35rem 0;
  border: 1px solid var(--border);
  border-top: 0;
  background: var(--page);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.nav-menu a {
  display: grid;
  grid-template-columns: 1.4rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  color: var(--link);
  text-decoration: none;
}

.nav-menu a:hover {
  background: var(--panel);
}

.nav-menu a:hover .menu-label {
  text-decoration: underline;
}

.nav-menu a[aria-current="page"] {
  background: var(--selected);
  font-weight: 600;
}

.nav-menu .glyph {
  width: 1.15rem;
  height: 1.15rem;
  color: var(--text-secondary);
}

.menu-count {
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.menu-group {
  margin-top: 0.25rem;
  border-top: 1px solid var(--border-light);
}

.menu-group-toggle {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.5rem 1rem 0.25rem;
  border: 0;
  background: none;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-align: left;
  text-transform: uppercase;
  cursor: pointer;
}

.menu-group-toggle::after {
  content: "";
  width: 0.4em;
  height: 0.4em;
  margin-left: 0.5em;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-135deg) translate(-0.1em, -0.1em);
}

.menu-group-toggle[aria-expanded="false"]::after {
  transform: rotate(45deg) translate(-0.1em, -0.1em);
}

.menu-group-toggle:hover {
  color: var(--text);
}

.menu-group a {
  padding-left: 1.75rem;
}

@media (max-width: 860px) {
  .brand-sub {
    display: none;
  }

  .brand-text {
    font-size: 1.5rem;
  }

  .menu-btn {
    display: inline-block;
  }

  .site-nav:not(.is-open) .nav-list {
    display: none;
  }

  .nav-list {
    flex-direction: column;
    padding: 0.25rem 0 0.5rem;
  }

  .nav-top {
    width: 100%;
    border-right: 0;
    text-align: left;
  }

  .nav-menu {
    position: static;
    min-width: 0;
    margin: 0 0.75rem 0.5rem;
    border: 1px solid var(--border);
    box-shadow: none;
  }
}

/* ----- Page heading ----- */

.main {
  flex: 1;
  padding-bottom: 3rem;
}

.breadcrumbs {
  padding-top: 0.9rem;
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  list-style: none;
}

.breadcrumbs li + li::before {
  content: "»";
  margin: 0 0.5rem;
}

.page-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  margin-bottom: 1.5rem;
  padding-top: 0.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.page-head--emblem {
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 1.25rem;
}

.page-head--emblem > :not(.page-emblem) {
  grid-column: 2;
}

.page-emblem {
  grid-column: 1;
  grid-row: 1 / span 6;
  display: block;
  width: 92px;
  height: 92px;
  padding: 6px;
  border: 1px solid var(--border);
  background: var(--media);
}

.page-emblem img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.page-kicker {
  margin: 0 0 0.25rem;
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.page-head h1 {
  margin-bottom: 0.4rem;
  font-size: clamp(1.75rem, 1.35rem + 1.4vw, 2.375rem);
}

.page-lead {
  max-width: 75ch;
  margin: 0;
  color: var(--text-secondary);
  font-size: 1.0625rem;
}

.page-holdings {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.5rem 0 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-top: 0.75rem;
}

@media (max-width: 600px) {
  .page-emblem {
    width: 64px;
    height: 64px;
  }
}

.section {
  padding-top: 0;
}

/* ----- Buttons ----- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0.4rem 1rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: linear-gradient(var(--page), var(--panel));
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--text-secondary);
  color: var(--text);
}

.btn-dark,
.btn-accent {
  border-color: var(--navy);
  background: var(--navy);
  color: var(--navy-text);
}

.btn-dark:hover,
.btn-accent:hover {
  background: var(--navy-dark);
  color: var(--navy-text);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

[data-load-more] {
  display: flex;
  margin: 1.5rem auto 0;
}

/* ----- Form controls ----- */

.filter-input,
.filter-select {
  width: 100%;
  min-height: 36px;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--page);
  color: var(--text);
  font-size: 0.875rem;
}

.filter-input:focus,
.filter-select:focus {
  border-color: var(--link);
}

.filter-input::placeholder {
  color: var(--text-secondary);
}

.filter-select:disabled {
  background: var(--panel);
  color: var(--text-secondary);
}

.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.6rem 0.75rem;
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border-light);
  background: var(--panel);
}

.filter-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 36px;
  font-size: 0.875rem;
  cursor: pointer;
}

.filter-check input {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  accent-color: var(--navy);
}

.region-tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0;
  margin-bottom: 0.6rem;
}

.region-tab {
  min-height: 32px;
  margin: 0 -1px -1px 0;
  padding: 0.2rem 0.8rem;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--link);
  font-size: 0.875rem;
  cursor: pointer;
}

.region-tab:hover {
  background: var(--panel);
  text-decoration: underline;
}

.region-tab.is-active {
  position: relative;
  z-index: 1;
  border-color: var(--navy);
  background: var(--navy);
  color: var(--navy-text);
}

.region-tab--sm {
  min-height: 28px;
  font-size: 0.8125rem;
}

.filter-toggle-btn {
  margin-left: auto;
  min-height: 32px;
  padding: 0.2rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: linear-gradient(var(--page), var(--panel));
  color: var(--text);
  font-size: 0.8125rem;
  cursor: pointer;
}

.filter-toggle-btn.is-open {
  border-color: var(--navy);
}

@media (max-width: 600px) {
  /* Tabs line up as an even grid instead of ragged wrapped rows. */
  .region-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(6.75rem, 1fr));
  }

  .region-tab {
    min-height: 40px;
    padding: 0.2rem 0.4rem;
  }

  .filter-toggle-btn {
    grid-column: 1 / -1;
    min-height: 40px;
    margin: 0.5rem 0 0;
    font-size: 0.875rem;
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }
}

/* ----- Catalog grids ----- */

.catalog-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.75rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-light);
}

.catalog-meta p {
  margin: 0;
  color: var(--text-secondary);
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 600;
}

.sort-control .filter-select {
  width: auto;
  min-width: 10rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1rem;
}

.archive-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-light);
  background: var(--page);
}

.archive-card:hover {
  border-color: var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.archive-card:focus-within {
  outline: 3px solid var(--focus);
}

.archive-card-media {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  padding: 0.75rem;
  overflow: hidden;
  border-bottom: 1px solid var(--border-light);
  background: var(--media);
}

.archive-card-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.flag-media img {
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.35));
}

.plate-media {
  aspect-ratio: 2 / 1;
}

.archive-card-placeholder {
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.archive-card-body {
  padding: 0.6rem 0.75rem 0.75rem;
}

.archive-card-title {
  margin: 0 0 0.2rem;
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.3;
}

/* The title is the card's button; its hit area covers the whole card. */
.archive-card-open {
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.archive-card-open::after {
  content: "";
  position: absolute;
  inset: 0;
}

.archive-card-open:focus-visible {
  outline: none;
}

.archive-card:hover .archive-card-open {
  color: var(--link-hover);
  text-decoration: underline;
}

.archive-card-meta {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.archive-card-notes {
  display: -webkit-box;
  margin: 0.25rem 0 0;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

@media (max-width: 600px) {
  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
  }

  .archive-card-media {
    padding: 0.5rem;
  }

  .archive-card-body {
    padding: 0.5rem 0.6rem 0.6rem;
  }

  .archive-card-title {
    font-size: 0.875rem;
  }

  .archive-card-meta,
  .archive-card-notes {
    font-size: 0.75rem;
  }
}

.empty-state {
  grid-column: 1 / -1;
  padding: 1.5rem;
  border: 1px solid var(--border-light);
  background: var(--panel);
  color: var(--text-secondary);
  list-style: none;
}

/* ----- Detail dialog ----- */

.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
}

.detail-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  width: min(980px, 100%);
  max-height: calc(100vh - 2 * var(--gutter));
  overflow: auto;
  border-top: 4px solid var(--navy);
  background: var(--page);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.detail-overlay--artwork .detail-panel {
  width: min(1200px, 100%);
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
}

.detail-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--page);
  color: var(--text);
  cursor: pointer;
}

.detail-img-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  padding: 1.5rem;
  border-right: 1px solid var(--border-light);
  background: var(--media);
}

.detail-img {
  max-width: 100%;
  max-height: 68vh;
  object-fit: contain;
  cursor: zoom-in;
}

.detail-body {
  padding: 1.5rem;
}

.detail-title {
  margin-right: 2.5rem;
  font-size: 1.5rem;
}

.detail-chips {
  margin-bottom: 0.75rem;
  color: var(--text-secondary);
}

.detail-notes:empty {
  display: none;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.detail-table td {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border-light);
  vertical-align: top;
}

.detail-label {
  width: 36%;
  background: var(--panel);
  font-weight: 600;
}

.detail-value {
  overflow-wrap: anywhere;
}

@media (max-width: 720px) {
  .detail-panel,
  .detail-overlay--artwork .detail-panel {
    grid-template-columns: 1fr;
  }

  .detail-img-wrap {
    min-height: 200px;
    border-right: 0;
    border-bottom: 1px solid var(--border-light);
  }
}

/* ----- Home: holdings table ----- */

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 2rem;
  align-items: start;
}

.holdings {
  width: 100%;
  border-collapse: collapse;
}

.holdings caption {
  padding-bottom: 0.5rem;
  font-family: var(--serif);
  font-size: 1.375rem;
  font-weight: 600;
  text-align: left;
}

.holdings th,
.holdings td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
  vertical-align: middle;
}

.holdings thead th {
  border-bottom: 2px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.holdings .holdings-group th {
  padding-top: 1.1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  color: var(--accent);
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.holdings .holdings-subgroup th {
  padding: 0.5rem 0.75rem 0.35rem;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.holdings-emblem {
  width: 72px;
}

.holdings-emblem span {
  display: block;
  width: 56px;
  height: 44px;
  padding: 3px;
  border: 1px solid var(--border-light);
  background: var(--media);
}

.holdings-emblem img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.holdings-name a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 1rem;
  font-weight: 600;
}

.holdings-name .glyph {
  color: var(--text-secondary);
}

.holdings-name p {
  margin: 0.1rem 0 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.holdings-count {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  text-align: right !important;
  white-space: nowrap;
}

.sidebar-box {
  margin-bottom: 1.25rem;
  border: 1px solid var(--border);
  background: var(--panel);
}

.sidebar-box h2 {
  margin: 0;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel-strong);
  font-family: var(--sans);
  font-size: 0.875rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.sidebar-box > div {
  padding: 0.75rem 0.85rem;
  font-size: 0.875rem;
}

.sidebar-box ul {
  margin: 0;
  padding-left: 1.1rem;
}

.sidebar-box p:last-child {
  margin-bottom: 0;
}

@media (max-width: 900px) {
  .home-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .holdings-count,
  .holdings thead {
    display: none;
  }

  .holdings-emblem {
    width: 60px;
  }
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.quick-card {
  display: block;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border-light);
  border-top: 3px solid var(--navy);
  background: var(--page);
  color: var(--text);
  text-decoration: none;
}

.quick-card:hover {
  border-color: var(--border);
  color: var(--text);
}

.quick-card-num {
  display: block;
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.quick-card-title {
  margin: 0.2rem 0;
  color: var(--link);
  font-size: 1.125rem;
  text-decoration: underline;
  text-decoration-thickness: 1px;
}

.quick-card-copy {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ----- Country directory and profiles ----- */

.country-card-topline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.country-card-flag {
  width: 48px;
  height: 32px;
  object-fit: contain;
  border: 1px solid var(--border-light);
  background: var(--media);
}

.country-card-meta {
  min-width: 0;
}

.country-card-chips {
  margin-top: 0.4rem;
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.chip {
  display: inline;
}

.chip + .chip::before {
  content: "\00a0· ";
}

.country-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.country-stat-card {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border-light);
  background: var(--panel);
  font-size: 0.875rem;
}

.country-stat-card strong {
  display: block;
  font-family: var(--serif);
  font-size: 1.75rem;
  line-height: 1.15;
}

.country-section {
  margin-bottom: 2.5rem;
}

.country-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
}

.country-section-head .t-h2 {
  margin: 0;
  font-size: 1.5rem;
}

.country-section-head p {
  margin: 0;
}

.country-section-note {
  color: var(--text-secondary);
}

.country-group,
.country-subgroup {
  margin-bottom: 1.5rem;
}

.country-group-head,
.country-subgroup-head {
  margin-bottom: 0.75rem;
}

.country-group-title,
.country-subgroup-title {
  margin: 0;
  font-size: 1.125rem;
}

.country-group-copy {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ----- Law readers ----- */

.laws-layout {
  display: grid;
  grid-template-columns: minmax(270px, 330px) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  gap: 1.25rem;
  align-items: start;
}

.laws-layout > .law-time-query--top {
  grid-column: 1 / -1;
}

.law-time-query {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.25rem 1.25rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border-light);
  background: var(--panel);
}

.law-time-query .law-time-label {
  grid-column: 1 / -1;
  margin: 0;
}

.law-time-label {
  display: block;
  margin: 0.75rem 0 0.2rem;
  font-family: var(--sans);
  font-size: 0.8125rem;
  font-weight: 600;
}

.law-time-controls {
  display: flex;
  gap: 0.5rem;
}

.law-time-controls .filter-input {
  width: 8rem;
}

.law-year-context {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.law-year-context p {
  margin: 0 0 0.5rem;
}

.law-year-nearby {
  margin: 0.25rem 0 0;
  padding-left: 1.25rem;
}

.law-year-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font: inherit;
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
}

.law-year-distance {
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

@media (max-width: 720px) {
  .law-time-query {
    grid-template-columns: 1fr;
  }
}

.laws-panel,
.manuals-panel {
  position: sticky;
  top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: calc(100vh - 1.5rem);
  min-height: 0;
}

.laws-panel > .law-time-label:first-child {
  margin-top: 0;
}

.law-category-description {
  margin: 0.25rem 0 0;
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.law-category-description:empty {
  display: none;
}

.law-filters,
.manuals-filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.manuals-filter-row--single {
  grid-template-columns: 1fr;
}

.law-count,
.manual-count {
  margin: 0.4rem 0 0;
  color: var(--text-secondary);
  font-family: var(--sans);
  font-size: 0.8125rem;
  font-weight: 600;
}

.law-list,
.manual-list {
  flex: 1;
  min-height: 240px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  list-style: none;
}

.law-list > li,
.manual-item {
  border-bottom: 1px solid var(--border-light);
}

.law-item-btn,
.manual-item-btn {
  display: block;
  width: 100%;
  padding: 0.5rem 0.6rem 0.5rem 0.75rem;
  border: 0;
  border-left: 3px solid transparent;
  background: var(--page);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.law-item-btn:hover,
.manual-item-btn:hover {
  background: var(--panel);
}

.law-item-btn.is-active,
.manual-item-btn.is-active {
  border-left-color: var(--navy);
  background: var(--selected);
}

.law-item-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.law-item-citation,
.manual-item-number {
  display: block;
  color: var(--link);
  font-size: 0.8125rem;
  font-weight: 600;
}

.law-item-year {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.law-item-title,
.manual-item-title {
  display: block;
  font-size: 0.875rem;
  line-height: 1.35;
}

.law-item-period,
.manual-item-meta {
  display: block;
  margin-top: 0.1rem;
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.law-item-period:empty {
  display: none;
}

.laws-viewer,
.manuals-viewer {
  min-width: 0;
  padding: 1.25rem 1.5rem 1.75rem;
  border: 1px solid var(--border);
}

.law-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.25rem;
}

.law-mode-group {
  display: inline-flex;
}

.law-mode-btn {
  min-height: 28px;
  margin-left: -1px;
  padding: 0.15rem 0.7rem;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--link);
  font-size: 0.8125rem;
  cursor: pointer;
}

.law-mode-btn.is-active {
  position: relative;
  border-color: var(--navy);
  background: var(--navy);
  color: var(--navy-text);
}

.law-title,
.manual-title {
  font-size: clamp(1.375rem, 1.15rem + 0.9vw, 1.875rem);
}

.law-citation {
  margin: 0 0 0.4rem;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.875rem;
}

.law-citation:empty {
  display: none;
}

.law-meta {
  margin-bottom: 0.6rem;
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.law-chip + .law-chip::before {
  content: "\00a0· ";
}

.law-summary {
  max-width: 72ch;
  color: var(--text-secondary);
  font-style: italic;
}

.law-content {
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
}

.law-content pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
}

.law-content .wp-main-doc {
  max-width: 72ch;
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.65;
}

.law-content .wp-main-doc h1,
.law-content .wp-main-doc h2,
.law-content .wp-main-doc h3,
.law-content .wp-main-doc h4 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.125rem;
  line-height: 1.3;
}

.law-content .wp-main-doc p,
.law-content .wp-main-doc div {
  margin: 0 0 0.75rem !important;
  text-align: left !important;
  text-indent: 0 !important;
}

.law-content .wp-main-doc ul,
.law-content .wp-main-doc ol {
  margin: 0 0 0.75rem;
  padding-left: 1.5rem;
}

.law-content .wp-main-doc span,
.law-content .wp-main-doc font {
  color: inherit !important;
  font-family: inherit !important;
  font-size: inherit !important;
  line-height: inherit !important;
}

.law-content .wp-main-doc table {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0 0 1rem;
  overflow-x: auto;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.8125rem;
}

.law-content .wp-main-doc td,
.law-content .wp-main-doc th {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border-light);
  vertical-align: top;
}

.law-content .wp-main-doc caption {
  margin-bottom: 0.25rem;
  color: var(--text-secondary);
  text-align: left;
}

.law-content .wp-main-doc .ecfr-node--section {
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-light);
}

.law-content .wp-main-doc .ecfr-meta,
.law-content .wp-main-doc .ecfr-footnote,
.law-content .wp-main-doc .ecfr-extract {
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--border);
  background: var(--panel);
  font-size: 0.9375rem;
}

.law-content .wp-main-doc .ecfr-meta-label {
  margin-bottom: 0.25rem;
  font-family: var(--sans);
  font-size: 0.8125rem;
}

.law-content .wp-main-doc .ecfr-meta--cita {
  color: var(--text-secondary);
}

.law-content .wp-main-doc .ecfr-stars {
  color: var(--text-secondary);
  letter-spacing: 0.25em;
}

.law-content .wp-main-doc sup,
.law-content .wp-main-doc sub {
  line-height: 0;
}

.law-content .wp-main-doc a {
  color: var(--link);
}

.law-content .wp-main-doc > *:first-child {
  margin-top: 0 !important;
}

/* ----- Military manuals ----- */

.manuals-layout {
  display: grid;
  grid-template-columns: minmax(270px, 350px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.manuals-panel .region-tabs {
  margin-bottom: 0.25rem;
}

.manual-list-empty {
  padding: 1rem;
  color: var(--text-secondary);
}

.manual-meta {
  margin: 0 0 0.6rem;
  color: var(--text-secondary);
  font-family: var(--sans);
  font-size: 0.8125rem;
}

.manual-notes {
  max-width: 80ch;
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

.manual-local-badge {
  margin: 0 0 0.5rem;
  color: var(--text-secondary);
  font-family: var(--sans);
  font-size: 0.75rem;
}

.manual-local-badge:empty {
  display: none;
}

.manual-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.manual-frame-wrap {
  position: relative;
  border: 1px solid var(--border);
  background: var(--panel);
}

.manual-frame {
  display: block;
  width: 100%;
  height: min(80vh, 1000px);
  border: 0;
}

.manual-frame-empty {
  padding: 3rem 1.5rem;
  color: var(--text-secondary);
  text-align: center;
}

@media (max-width: 900px) {
  .laws-layout,
  .manuals-layout {
    grid-template-columns: 1fr;
  }

  .laws-panel,
  .manuals-panel {
    position: static;
    max-height: none;
  }

  .law-list,
  .manual-list {
    max-height: 50vh;
  }

  .laws-viewer,
  .manuals-viewer {
    padding: 1rem;
  }

  .manual-frame {
    height: 70vh;
  }
}

/* ----- Footer ----- */

.site-footer {
  margin-top: auto;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.site-footer .wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
}

.site-footer p {
  margin: 0;
}

.site-footer ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
