.modal-window {
  position: fixed;
  background-color: #00000080;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 999;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s;
}
.modal-window:target {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}
.modal-window > div {
  border-radius: 20px;
  width: 400px;
  max-width: 95vw;
  max-height: 92vh;
  overflow-y: auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 2em;
  background: white;
}
@media (max-width: 480px) {
  .modal-window > div {
    width: 95%;
    padding: 1.25em;
  }
}
.modal-window header {
  font-weight: bold;
}
.modal-window h1 {
  font-size: 150%;
  margin: 0 0 15px;
}

/* Standardized rotating X close — used by every modal in the app. The X
   glyph comes from the ::before pseudo-element, so legacy markup that
   still says "Close" or "&times;" inline renders identically (the inline
   text is suppressed via font-size: 0 on the link itself). */
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #8392ab;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid transparent;
  font-size: 0;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  transition: background 160ms ease, color 160ms ease, transform 200ms ease, border-color 160ms ease;
  z-index: 10;
}
.modal-close::before {
  content: '\00d7';
  font-size: 1.4rem;
  line-height: 1;
  font-weight: 300;
}
.modal-close:hover,
.modal-close:focus-visible {
  outline: none;
  background: rgba(0, 0, 0, 0.08);
  color: #344767;
  border-color: rgba(0, 0, 0, 0.06);
  transform: rotate(90deg);
}

/* Search trigger button — styled like an input but actually a button.
   Opens the native <dialog> search palette. */
.search-trigger {
  display: inline-flex; align-items: center; gap: 0.55rem;
  padding: 0.45rem 0.85rem 0.45rem 0.85rem;
  min-width: 240px; max-width: 320px;
  background: #fff; border: 1px solid #e1e4ea; border-radius: 8px;
  color: #8392ab; font-size: 0.84rem; font-weight: 400;
  cursor: pointer; text-align: left;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.search-trigger:hover { border-color: #cfd4dc; }
.search-trigger:focus-visible { outline: 0; border-color: #5e72e4; box-shadow: 0 0 0 3px rgba(94,114,228,0.15); }
.search-trigger > i { color: #8392ab; font-size: 0.85rem; }
.search-trigger-label { flex: 1; }
.search-trigger-kbd { display: inline-flex; gap: 2px; }
.search-trigger-kbd kbd {
  display: inline-block; min-width: 1.1rem; text-align: center;
  padding: 0.02rem 0.3rem; background: #f6f8fb; border: 1px solid #e1e4ea;
  border-radius: 4px; color: #67748e; font-family: inherit;
  font-size: 0.66rem; font-weight: 600;
}

/* Native <dialog> command palette. Browser handles backdrop, focus trap,
   and Escape natively via dialog.showModal(). */
dialog#search-dialog {
  padding: 0; border: 0; border-radius: 12px;
  width: 640px; max-width: calc(100vw - 2rem);
  max-height: 76vh;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.32), 0 2px 6px rgba(15, 23, 42, 0.06);
  background: #fff; color: #1a2540;
  margin: 12vh auto auto;
  overflow: hidden;
  display: none;
}
dialog#search-dialog[open] {
  display: flex; flex-direction: column;
}
dialog#search-dialog::backdrop {
  background: rgba(20, 30, 60, 0.42);
  backdrop-filter: blur(2px);
}

.sd-input-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.85rem 3.25rem 0.85rem 1rem;
  border-bottom: 1px solid #eef0f4;
  flex-shrink: 0;
}
.sd-input-icon { color: #8392ab; font-size: 1rem; }
.sd-input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font-size: 1rem; color: #1a2540; padding: 0; font-family: inherit;
}
.sd-input::placeholder { color: #a3aab9; }

.sd-results {
  overflow-y: auto; flex: 1 1 auto; padding: 0.4rem 0; min-height: 0;
}
.sd-tip   { padding: 1.8rem 1rem; color: #8392ab; font-size: 0.84rem; text-align: center; }
.sd-empty { padding: 1.5rem 1rem; color: #67748e; font-size: 0.86rem; text-align: center; }

.sd-section { padding: 0.2rem 0; }
.sd-section + .sd-section { border-top: 1px solid #f1f3f6; margin-top: 0.2rem; padding-top: 0.5rem; }
.sd-section-label {
  font-size: 0.7rem; font-weight: 600; color: #67748e;
  padding: 0.4rem 1rem 0.25rem;
}

.sd-row {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.55rem 1rem; text-decoration: none; color: inherit;
  border-left: 2px solid transparent;
  transition: background 100ms ease;
}
.sd-row:hover, .sd-row.sd-row-active {
  background: #f3f6fc; border-left-color: #5e72e4; text-decoration: none;
}
.sd-row-icon { color: #5e72e4; font-size: 0.95rem; width: 1.3rem; flex-shrink: 0; text-align: center; }
.sd-row-body { flex: 1 1 auto; min-width: 0; }
.sd-row-title {
  font-size: 0.93rem; font-weight: 500; color: #1a2540;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sd-row-title mark { background: #fff3c4; color: #1a2540; padding: 0; border-radius: 2px; }
.sd-row-snippet {
  font-size: 0.76rem; color: #67748e; margin-top: 0.1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sd-row-snippet mark { background: #fff3c4; color: #344767; padding: 0; }
.sd-row-arrow { color: #cfd4dc; font-size: 0.78rem; opacity: 0; transition: opacity 120ms ease, transform 120ms ease; }
.sd-row:hover .sd-row-arrow, .sd-row.sd-row-active .sd-row-arrow { opacity: 1; transform: translateX(2px); color: #5e72e4; }

.sd-see-all {
  display: flex; justify-content: center; align-items: center; gap: 0.4rem;
  padding: 0.65rem 1rem; margin-top: 0.3rem;
  color: #5e72e4; font-size: 0.82rem; font-weight: 600;
  background: #fafbff; border-top: 1px solid #eef0f4;
  text-decoration: none;
}
.sd-see-all:hover, .sd-see-all.sd-row-active { background: #eef1ff; color: #344767; }

.sd-footer {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.5rem 1rem; border-top: 1px solid #eef0f4;
  font-size: 0.72rem; color: #67748e; background: #fafbff;
  flex-shrink: 0;
}
.sd-footer-spacer { flex: 1 1 auto; }
.sd-footer-hint { color: #8392ab; }
.sd-footer kbd {
  display: inline-block; min-width: 1.2rem; text-align: center;
  padding: 0.04rem 0.35rem; margin: 0 0.08rem;
  background: #fff; border: 1px solid #e1e4ea; border-radius: 4px;
  font-family: inherit; font-size: 0.7rem; font-weight: 600;
  color: #344767; box-shadow: 0 1px 0 rgba(20, 30, 60, 0.04);
}

@media (max-width: 640px) {
  dialog#search-dialog { width: calc(100vw - 1rem); margin-top: 5vh; max-height: 90vh; }
  .sd-footer-hint { display: none; }
  .search-trigger { min-width: 0; }
  .search-trigger-kbd { display: none; }
}

/* Command palette — Cloudflare-style centered modal that escapes every
   stacking context by living at document.body root. */
.cmd-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 30, 60, 0.42);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 99998;
  opacity: 0; visibility: hidden;
  transition: opacity 140ms ease, visibility 140ms ease;
}
.cmd-backdrop.cmd-show { opacity: 1; visibility: visible; }

.cmd-palette {
  position: fixed; top: 12vh; left: 50%;
  transform: translateX(-50%) translateY(-6px);
  width: 640px; max-width: calc(100vw - 2rem);
  background: #fff; border-radius: 12px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.32), 0 2px 6px rgba(15, 23, 42, 0.06);
  z-index: 99999;
  opacity: 0; visibility: hidden;
  transition: opacity 140ms ease, visibility 140ms ease, transform 140ms ease;
  overflow: hidden;
  display: flex; flex-direction: column;
  max-height: 76vh;
}
.cmd-palette.cmd-show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }

.cmd-input-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #eef0f4;
}
.cmd-input-icon { color: #8392ab; font-size: 1rem; }
.cmd-input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font-size: 1rem; color: #1a2540; padding: 0;
}
.cmd-input::placeholder { color: #a3aab9; }
.cmd-esc {
  border: 1px solid #e1e4ea; background: #fff; color: #67748e;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em;
  padding: 0.18rem 0.55rem; border-radius: 6px; cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.cmd-esc:hover { background: #f6f8fb; border-color: #cfd4dc; }

.cmd-results {
  overflow-y: auto; flex: 1 1 auto; padding: 0.4rem 0;
  scrollbar-width: thin;
}
.cmd-results::-webkit-scrollbar { width: 10px; }
.cmd-results::-webkit-scrollbar-thumb { background: #e1e4ea; border-radius: 6px; }

.cmd-tip { padding: 1.8rem 1rem; color: #8392ab; font-size: 0.84rem; text-align: center; }
.cmd-empty { padding: 1.5rem 1rem; color: #67748e; font-size: 0.86rem; text-align: center; }

.cmd-section { padding: 0.2rem 0; }
.cmd-section + .cmd-section { border-top: 1px solid #f1f3f6; margin-top: 0.2rem; padding-top: 0.5rem; }
.cmd-section-label {
  font-size: 0.7rem; font-weight: 600; color: #67748e;
  padding: 0.4rem 1rem 0.25rem;
}

.cmd-row {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.55rem 1rem; text-decoration: none; color: inherit;
  border-left: 2px solid transparent;
  transition: background 100ms ease;
}
.cmd-row:hover, .cmd-row.cmd-row-active {
  background: #f3f6fc; border-left-color: #5e72e4; text-decoration: none;
}
.cmd-row-icon {
  color: #5e72e4; font-size: 0.95rem;
  width: 1.3rem; flex-shrink: 0; text-align: center;
}
.cmd-row-body { flex: 1 1 auto; min-width: 0; }
.cmd-row-title {
  font-size: 0.93rem; font-weight: 500; color: #1a2540;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cmd-row-title mark {
  background: #fff3c4; color: #1a2540; padding: 0; border-radius: 2px;
}
.cmd-row-snippet {
  font-size: 0.76rem; color: #67748e; margin-top: 0.1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cmd-row-snippet mark { background: #fff3c4; color: #344767; padding: 0; }
.cmd-row-arrow {
  color: #cfd4dc; font-size: 0.78rem; opacity: 0;
  transition: opacity 120ms ease, transform 120ms ease;
}
.cmd-row:hover .cmd-row-arrow,
.cmd-row.cmd-row-active .cmd-row-arrow { opacity: 1; transform: translateX(2px); color: #5e72e4; }

.cmd-see-all {
  display: flex; justify-content: center; align-items: center; gap: 0.4rem;
  padding: 0.65rem 1rem; margin-top: 0.3rem;
  color: #5e72e4; font-size: 0.82rem; font-weight: 600;
  background: #fafbff; border-top: 1px solid #eef0f4;
  text-decoration: none;
}
.cmd-see-all:hover, .cmd-see-all.cmd-row-active { background: #eef1ff; color: #344767; }

.cmd-footer {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.5rem 1rem; border-top: 1px solid #eef0f4;
  font-size: 0.72rem; color: #67748e; background: #fafbff;
}
.cmd-footer-spacer { flex: 1 1 auto; }
.cmd-footer-hint { color: #8392ab; }
.cmd-footer kbd {
  display: inline-block; min-width: 1.2rem; text-align: center;
  padding: 0.04rem 0.35rem; margin: 0 0.08rem;
  background: #fff; border: 1px solid #e1e4ea; border-radius: 4px;
  font-family: inherit; font-size: 0.7rem; font-weight: 600;
  color: #344767; box-shadow: 0 1px 0 rgba(20, 30, 60, 0.04);
}

@media (max-width: 640px) {
  .cmd-palette { top: 5vh; width: calc(100vw - 1rem); max-height: 90vh; }
  .cmd-footer-hint { display: none; }
}

/* The navbar input is now a trigger that opens the palette. */
#search { cursor: pointer; caret-color: transparent; }

/* Search results page */
.search-page .sr-card {
  background: #fff; border: 1px solid #eef0f4; border-radius: 0.9rem;
  box-shadow: 0 2px 8px rgba(20,30,60,0.04);
  overflow: hidden;
}
.search-page .sr-card-header {
  padding: 0.75rem 1rem;
  display: flex; justify-content: space-between; align-items: center;
  background: #fafbff; border-bottom: 1px solid #eef0f4;
}
.search-page .sr-card-title { font-weight: 700; color: #1a2540; font-size: 0.92rem; }
.search-page .sr-section-icon { color: #5e72e4; font-size: 0.95rem; }
.search-page .sr-count {
  font-size: 0.7rem; font-weight: 700; color: #67748e;
  background: #eef0f4; padding: 0.1rem 0.5rem; border-radius: 999px;
}
.search-page .sr-see-all {
  font-size: 0.78rem; font-weight: 600; color: #5e72e4;
  text-decoration: none;
}
.search-page .sr-see-all:hover { color: #344767; }
.search-page .sr-hit { border-bottom: 1px solid #f3f5f8; }
.search-page .sr-hit:last-child { border-bottom: 0; }
.search-page .sr-hit-link {
  display: block; padding: 0.7rem 1rem; text-decoration: none;
  border-left: 3px solid transparent; transition: background 120ms ease, border-color 120ms ease;
}
.search-page .sr-hit-link:hover {
  background: #f6f8fb; border-left-color: #5e72e4;
}
.search-page .sr-hit-title { font-size: 0.92rem; font-weight: 600; color: #1a2540; }
.search-page .sr-hit-snippet { font-size: 0.78rem; color: #67748e; margin-top: 0.15rem; line-height: 1.4; }
.search-page .sr-empty {
  padding: 1.5rem; text-align: center; color: #8392ab; font-size: 0.88rem;
}
.search-page .sr-empty-card {
  padding: 3rem 1rem; text-align: center;
}
.search-page .sr-pager .btn { min-width: 7rem; }
