/* ── Nav trigger ── */
.search {
  cursor: pointer;
  position: absolute;
  left: 280px;
  top: 0;
  z-index: 11;
  padding: 10px 40px;
  width: calc(100% - 280px - 220px);
  max-width: 480px;
  box-sizing: border-box;
}

body.close .search {
  left: 0;
  width: calc(100% - 220px);
  max-width: 480px;
  padding: 10px 40px;
}

.search .search-trigger-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border: 1px solid var(--border-light, #eee);
  border-radius: 8px;
  background: var(--bg-sidebar, #f4f7fb);
  color: #6b7685;
  font-size: 15px;
  font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
  transition: border-color 0.15s, background-color 0.15s;
  white-space: nowrap;
  width: 100%;
}

.search .search-trigger-wrap:hover {
  border-color: #ccc;
  background-color: var(--bg-table-odd, #fbfcfd);
}

.search .search-trigger-wrap .search-icon {
  width: 16px;
  height: 16px;
  display: block;
  flex-shrink: 0;
}

.search .search-trigger-wrap .search-icon:before {
  content: '';
  display: block;
  width: 16px;
  height: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M14.386 14.386l4.088 4.088' stroke='%236b7685' stroke-width='2' stroke-linecap='round'/%3E%3Ccircle cx='9' cy='9' r='7' stroke='%236b7685' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

.search-trigger-text {
  user-select: none;
  flex: 1;
}

.search-trigger-kbd {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  font-size: 12px;
  font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
  color: #6b7685;
  background: var(--bg-body, #fff);
  border: 1px solid var(--border-light, #eee);
  border-radius: 4px;
  line-height: 1.4;
  margin-left: auto;
}

/* ── Modal overlay ── */
.search-modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
}

.search-modal-overlay.open {
  display: block;
}

.search-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  animation: searchFadeIn 0.15s ease-out;
}

@keyframes searchFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes searchSlideIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Modal container ── */
.search-modal-container {
  position: relative;
  max-width: 640px;
  width: calc(100% - 40px);
  margin: 15vh auto 0;
  background: var(--bg-body, #fff);
  border-radius: 12px;
  box-shadow: 0 16px 70px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  max-height: 70vh;
  overflow: hidden;
  animation: searchSlideIn 0.15s ease-out;
}

/* ── Header / Input ── */
.search-modal-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light, #eee);
  gap: 12px;
}

.search-modal-icon {
  flex-shrink: 0;
  color: #6b7685;
}

.search-modal-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 16px;
  font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
  color: var(--text-primary, #3E4550);
  background: transparent;
  line-height: 1.5;
}

.search-modal-input::placeholder {
  color: #6b7685;
}

.search-modal-esc {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  font-size: 12px;
  font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
  color: #6b7685;
  background: var(--bg-sidebar, #f4f7fb);
  border: 1px solid var(--border-light, #eee);
  border-radius: 4px;
  line-height: 1.4;
}

/* ── Body / Results ── */
.search-modal-body {
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}

.search-modal-body:not(:has(.search-modal-group)):not(:has(.search-modal-empty)):not(:has(.search-modal-recent)) {
  display: none;
}

.search-modal-empty {
  text-align: center;
  padding: 40px 20px;
  color: #6b7685;
  font-size: 14px;
  margin: 0;
}

/* ── Recent searches ── */
.search-modal-recent {
  padding: 0 8px;
}

.search-modal-recent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7685;
}

.search-modal-recent-clear {
  background: none;
  border: none;
  color: var(--color-primary, #0089C0);
  font-size: 12px;
  font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
  cursor: pointer;
  padding: 0;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}

.search-modal-recent-clear:hover {
  text-decoration: underline;
}

.search-modal-item--recent .search-modal-item-icon-wrap {
  background: transparent;
  color: #9ba4ae;
}

.search-modal-item--recent:hover .search-modal-item-icon-wrap,
.search-modal-item--recent.selected .search-modal-item-icon-wrap {
  background: transparent;
  color: var(--color-primary, #0089C0);
}

/* ── Page groups ── */
.search-modal-group {
  padding: 0 8px;
}

.search-modal-group + .search-modal-group {
  margin-top: 4px;
}

.search-modal-group-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7685;
  padding: 10px 12px 4px;
}

/* ── Result items ── */
.search-modal-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background-color 0.1s;
  border-left: 3px solid transparent;
}

.search-modal-item:hover,
.search-modal-item.selected {
  background-color: var(--bg-sidebar, #f4f7fb);
  border-left-color: var(--color-primary, #0089C0);
}

/* ── Icon ── */
.search-modal-item-icon-wrap {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--bg-sidebar, #f4f7fb);
  color: #6b7685;
}

.search-modal-item-icon {
  width: 16px;
  height: 16px;
}

.search-modal-item:hover .search-modal-item-icon-wrap,
.search-modal-item.selected .search-modal-item-icon-wrap {
  background: var(--color-primary, #0089C0);
  color: #fff;
}

/* ── Arrow ── */
.search-modal-item-arrow {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: #6b7685;
  opacity: 0;
  transition: opacity 0.1s;
}

.search-modal-item:hover .search-modal-item-arrow,
.search-modal-item.selected .search-modal-item-arrow {
  opacity: 1;
  color: var(--color-primary, #0089C0);
}

/* ── Content ── */
.search-modal-item-content {
  flex: 1;
  min-width: 0;
}

.search-modal-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #3E4550);
  margin-bottom: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-modal-item-snippet {
  font-size: 12px;
  color: #6b7685;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Page-level vs section-level variants ── */
.search-modal-item--page {
  padding-top: 10px;
  padding-bottom: 10px;
}

.search-modal-item--page .search-modal-item-title {
  font-size: 15px;
}

.search-modal-item--page .search-modal-item-snippet {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.search-modal-item--section .search-modal-item-icon-wrap {
  width: 24px;
  height: 24px;
  background: transparent;
  color: #9ba4ae;
}

.search-modal-item--section .search-modal-item-icon {
  width: 14px;
  height: 14px;
}

.search-modal-item--section:hover .search-modal-item-icon-wrap,
.search-modal-item--section.selected .search-modal-item-icon-wrap {
  background: transparent;
  color: var(--color-primary, #0089C0);
}

.search-modal-item .search-keyword {
  color: var(--color-primary, #0089C0);
  font-style: normal;
  font-weight: 600;
}

/* ── Footer ── */
.search-modal-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  border-top: 1px solid var(--border-light, #eee);
  font-size: 13px;
  color: #6b7685;
}

.search-modal-hint {
  display: flex;
  align-items: center;
  gap: 4px;
}

.search-modal-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 2px 6px;
  font-size: 12px;
  font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
  color: #6b7685;
  background: var(--bg-sidebar, #f4f7fb);
  border: 1px solid var(--border-light, #eee);
  border-radius: 3px;
  line-height: 1.4;
}

/* ── Legacy overrides: hide old search infrastructure ── */
body > .searching-layer {
  display: none !important;
}

html[data-theme="dark"] .search-modal-recent-header {
  color: var(--text-secondary, #8b949e);
}

html[data-theme="dark"] .search-modal-recent-clear {
  color: var(--color-primary, #58a6ff);
}

html[data-theme="dark"] .search-modal-item--recent .search-modal-item-icon-wrap {
  color: #484f58;
}

html[data-theme="dark"] .search-modal-item--recent:hover .search-modal-item-icon-wrap,
html[data-theme="dark"] .search-modal-item--recent.selected .search-modal-item-icon-wrap {
  color: var(--color-primary, #58a6ff);
}

/* ── Responsive ── */
@media screen and (max-width: 1100px) {
  .search {
    padding: 10px 20px;
    width: calc(100% - 280px - 200px);
  }

  body.close .search {
    padding: 10px 20px;
    width: calc(100% - 200px);
  }
}

@media screen and (max-width: 768px) {
  .search {
    padding: 10px 16px;
    width: calc(100% - 280px - 160px);
    max-width: none;
  }

  body.close .search {
    padding: 10px 16px;
    width: calc(100% - 160px);
    max-width: none;
  }

  .search-modal-container {
    margin: 10vh auto 0;
    width: calc(100% - 20px);
    max-height: 80vh;
  }

  .search-trigger-text {
    display: none;
  }

  .search-trigger-kbd {
    display: none;
  }

  .search-modal-footer {
    display: none;
  }
}
