/* Player search — one box on every page (player_search_plan.md).
   Markup: templates/includes/search_box.html (box) and
   templates/includes/search_results.html (server-rendered rows); the
   dropdown is built by static/search/cp-search.js with the same classes. */

.cp-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.cp-search-field {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}

.cp-search-field > i {
  position: absolute;
  left: 12px;
  pointer-events: none;
  font-size: 14px;
}

.cp-search-input {
  width: 100%;
  min-height: 38px;
  padding: 6px 12px 6px 34px;
  border-radius: var(--radius-button, 6px);
  font-family: var(--font-family);
  font-size: 14px;
  outline: none;
}

.cp-search-input::-webkit-search-cancel-button { cursor: pointer; }

/* --- navbar variant (the navbar is always dark) --- */
.cp-search--nav { flex: 1; max-width: 420px; margin: 0 12px; }
.cp-search--nav .cp-search-field > i { color: var(--color-zinc); }
.cp-search--nav .cp-search-input {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--color-surface);
}
.cp-search--nav .cp-search-input::placeholder { color: var(--color-zinc); }
.cp-search--nav .cp-search-input:focus { border-color: var(--color-gold); }
.cp-search-kbd {
  position: absolute;
  right: 10px;
  font-size: 12px;
  line-height: 1;
  padding: 3px 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  color: var(--color-zinc);
  pointer-events: none;
}
.cp-search-input:focus ~ .cp-search-kbd,
.cp-search-input:not(:placeholder-shown) ~ .cp-search-kbd { display: none; }

/* Phones: an icon that opens the box as a full-width sheet under the navbar */
.cp-search-open {
  display: none;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-button, 6px);
  color: var(--color-zinc);
  min-width: 40px;
  min-height: 40px;
  margin-left: auto;
  margin-right: 8px;
}

@media (max-width: 991.98px) {
  .navbar { position: relative; }
  .cp-search-open { display: inline-flex; align-items: center; justify-content: center; }
  .cp-search--nav {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 1050;
    max-width: none;
    margin: 0;
    padding: 10px 16px;
    background: var(--color-dark);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }
  .cp-search--nav.is-open { display: flex; }
  .cp-search-kbd { display: none; }
  /* iOS Safari zooms the page when a control under 16px takes focus */
  .cp-search-input { font-size: 16px; }
}

body[data-theme="dark"] .cp-search--nav { background-color: transparent; }
@media (max-width: 991.98px) {
  body[data-theme="dark"] .cp-search--nav { background: var(--color-dark-surface); }
}

/* --- hero variant (/search, /player landing) --- */
.cp-search--hero .cp-search-input {
  min-height: 48px;
  font-size: 16px;
  background: #fff;
  border: 1px solid rgba(44, 49, 57, 0.2);
  color: var(--color-dark);
}
.cp-search--hero .cp-search-input:focus { border-color: var(--color-gold); }
.cp-search--hero .cp-search-field > i { color: var(--color-steel); }
.cp-search-hint { font-size: 13px; color: var(--color-steel); margin: 6px 0 0; }
body[data-theme="dark"] .cp-search--hero .cp-search-input {
  background: var(--color-dark-surface);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--color-dark-text);
}
body[data-theme="dark"] .cp-search-hint { color: var(--color-zinc); }

/* --- dropdown --- */
.cp-search-dd {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(560px, calc(100vw - 32px));
  z-index: 1060;
  background: #fff;
  color: var(--color-dark);
  border: 1px solid rgba(44, 49, 57, 0.15);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  text-align: left;
}
.cp-search--hero .cp-search-dd { left: 0; right: auto; width: 100%; }
@media (max-width: 991.98px) {
  .cp-search--nav .cp-search-dd { left: 16px; right: 16px; width: auto; }
}
body[data-theme="dark"] .cp-search-dd {
  background: var(--color-dark-surface);
  color: var(--color-dark-text);
  border-color: rgba(255, 255, 255, 0.1);
}

/* --- rows (dropdown and server-rendered lists) --- */
.cp-search-results { list-style: none; margin: 0; padding: 0; }
.cp-search-lane {
  font-size: 12px;
  letter-spacing: var(--letter-spacing-small-label, 0.04em);
  text-transform: uppercase;
  color: var(--color-steel);
  padding: 10px 14px 4px;
}
.cp-search-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px 14px;
  border-top: 1px solid rgba(44, 49, 57, 0.08);
  color: inherit;
  text-decoration: none;
}
.cp-search-row:hover,
.cp-search-row[aria-selected="true"] {
  background: rgba(197, 150, 62, 0.12);
  color: inherit;
}
.cp-search-tile {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  background: var(--color-tawny-light);
  color: var(--color-gold-deep);
}
.cp-search-tile--chesscom { background: #dcebd0; color: #3b6d11; }
.cp-search-tile--lichess { background: #e3e3e3; color: #2c2c2a; }
.cp-search-main { flex: 1; min-width: 0; }
.cp-search-name {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cp-search-name mark { background: rgba(197, 150, 62, 0.35); color: inherit; padding: 0; }
.cp-search-meta {
  font-size: 12px;
  color: var(--color-steel);
  display: flex;
  flex-wrap: wrap;
  gap: 2px 8px;
  align-items: center;
}
.cp-search-title {
  font-size: 12px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--color-gold);
  color: #fff;
  margin-right: 4px;
  vertical-align: 1px;
}
.cp-search-id {
  font-size: 12px;
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid rgba(44, 49, 57, 0.15);
}
.cp-search-id--unconfirmed { opacity: 0.75; border-style: dashed; }
.cp-search-rating { flex: none; font-size: 15px; font-weight: 600; min-width: 40px; text-align: right; }
.cp-search-go { flex: none; color: var(--color-zinc); }
.cp-search-empty { padding: 12px 14px; font-size: 13px; color: var(--color-steel); }
.cp-search-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 44px;
  padding: 8px 14px;
  border-top: 1px solid rgba(44, 49, 57, 0.08);
  font-size: 13px;
  color: var(--color-steel);
  text-decoration: none;
}
.cp-search-footer:hover,
.cp-search-footer[aria-selected="true"] { background: rgba(197, 150, 62, 0.12); color: inherit; }

body[data-theme="dark"] .cp-search-row,
body[data-theme="dark"] .cp-search-footer { border-top-color: rgba(255, 255, 255, 0.07); }
body[data-theme="dark"] .cp-search-meta,
body[data-theme="dark"] .cp-search-lane,
body[data-theme="dark"] .cp-search-empty,
body[data-theme="dark"] .cp-search-footer { color: var(--color-zinc); }
body[data-theme="dark"] .cp-search-id { border-color: rgba(255, 255, 255, 0.18); }
body[data-theme="dark"] .cp-search-tile { background: rgba(197, 150, 62, 0.2); color: var(--color-dark-gold); }
body[data-theme="dark"] .cp-search-tile--chesscom { background: rgba(99, 153, 34, 0.25); color: #c0dd97; }
body[data-theme="dark"] .cp-search-tile--lichess { background: rgba(255, 255, 255, 0.1); color: var(--color-dark-text); }

/* --- source chips (Database · Chess.com · Lichess) --- */
.cp-search-chips { display: flex; gap: 6px; padding: 10px 14px; overflow-x: auto; scrollbar-width: none; }
.cp-search-chips::-webkit-scrollbar { display: none; }  /* still swipes on phones */
.cp-search-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
  border-radius: 999px;
  border: 1px solid rgba(44, 49, 57, 0.2);
  background: transparent;
  color: var(--color-steel);
  text-decoration: none;
  cursor: pointer;
}
.cp-search-chip[aria-pressed="true"] {
  background: rgba(197, 150, 62, 0.16);
  border-color: var(--color-gold);
  color: var(--color-gold-deep);
}
body[data-theme="dark"] .cp-search-chip { border-color: rgba(255, 255, 255, 0.18); color: var(--color-zinc); }
body[data-theme="dark"] .cp-search-chip[aria-pressed="true"] { color: var(--color-dark-gold); border-color: var(--color-dark-gold); }

/* Server-rendered result list (/search, /player?q=) */
.cp-search-list {
  border: 1px solid rgba(44, 49, 57, 0.12);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.cp-search-list .cp-search-row:first-child,
.cp-search-list .cp-search-lane + .cp-search-row { border-top-width: 1px; }
body[data-theme="dark"] .cp-search-list { background: var(--color-dark-surface); border-color: rgba(255, 255, 255, 0.1); }
