/* ════════════════════════════════════════════════════════════════
   MuzamMaths — site-wide search (mm-search.js)
   Nav button, home-page search bar, and the search dialog.
   Uses the page's colour tokens with safe fallbacks.
   ════════════════════════════════════════════════════════════════ */

/* ── Nav button ───────────────────────────────────────────────── */
.mm-search-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 10px 0 12px; border-radius: 999px;
  border: 1px solid var(--border2, #C2D4E8); background: var(--bg2, #F8FAFF);
  color: var(--n-700, #334155); font: 500 13px 'DM Sans', sans-serif; cursor: pointer;
  transition: border-color var(--ease, .15s), background var(--ease, .15s), box-shadow var(--ease, .15s);
}
.mm-search-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.mm-search-btn:hover { border-color: var(--pri-accent, #2563EB); background: #fff; box-shadow: 0 2px 10px rgba(30, 64, 175, .12); }
.mm-search-btn:focus-visible { outline: 2px solid var(--pri-accent, #2563EB); outline-offset: 2px; }
.mm-search-btn kbd {
  font: 600 10px 'DM Sans', sans-serif; color: var(--n-500, #64748B);
  border: 1px solid var(--n-200, #E2E8F0); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; background: #fff;
}
@media (max-width: 1180px) { .mm-search-btn .mm-search-lbl, .mm-search-btn kbd { display: none; } .mm-search-btn { width: 38px; height: 38px; padding: 0; justify-content: center; } }

/* Phone menu entry */
.mm-menu-panel .mm-menu-search {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 1px solid var(--border2, #C2D4E8); border-radius: 12px; background: var(--bg2, #F8FAFF);
  padding: 12px 14px; margin-bottom: 6px; font: 500 15px 'DM Sans', sans-serif; color: var(--n-500, #64748B); cursor: pointer;
}
.mm-menu-panel .mm-menu-search svg { width: 18px; height: 18px; }

/* ── Home-page search bar ─────────────────────────────────────── */
.mm-hero-search {
  display: flex; align-items: center; gap: 10px; max-width: 560px; margin: 22px 0 6px;
  background: #fff; border: 1.5px solid rgba(255, 255, 255, .55); border-radius: 16px;
  padding: 6px 6px 6px 16px; box-shadow: 0 10px 30px rgba(4, 20, 50, .22);
}
.mm-hero-search svg { width: 20px; height: 20px; color: var(--n-500, #64748B); flex-shrink: 0; }
.mm-hero-search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font: 500 15px 'DM Sans', sans-serif; color: var(--n-900, #0F172A); height: 44px;
}
.mm-hero-search input::placeholder { color: var(--n-500, #64748B); }
.mm-hero-search button {
  height: 44px; padding: 0 20px; border: 0; border-radius: 11px; cursor: pointer;
  background: var(--pri, #1E40AF); color: #fff; font: 600 14px 'DM Sans', sans-serif;
}
.mm-hero-search button:hover { background: var(--pri-hover, #1D4ED8); }
.mm-hero-search:focus-within { border-color: var(--amber-border, #EF9F27); box-shadow: 0 0 0 4px rgba(239, 159, 39, .25), 0 10px 30px rgba(4, 20, 50, .22); }
@media (max-width: 560px) { .mm-hero-search button { padding: 0 14px; } .mm-hero-search input { font-size: 14px; } }

/* ── Dialog ───────────────────────────────────────────────────── */
html.mm-search-open { overflow: hidden; }
.mm-search { position: fixed; inset: 0; z-index: 2000; display: flex; justify-content: center; align-items: flex-start; padding: 9vh 16px 16px; }
.mm-search[hidden] { display: none; }
.mm-search-scrim { position: absolute; inset: 0; background: rgba(4, 20, 50, .55); backdrop-filter: blur(3px); }
.mm-search-panel {
  position: relative; width: 100%; max-width: 680px; max-height: 76vh; display: flex; flex-direction: column;
  background: #fff; border-radius: 18px; box-shadow: 0 30px 80px rgba(4, 20, 50, .35); overflow: hidden;
  animation: mmSearchIn .16s ease-out;
}
@keyframes mmSearchIn { from { opacity: 0; transform: translateY(-8px) scale(.985); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .mm-search-panel { animation: none; } }

.mm-search-bar { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--n-200, #E2E8F0); }
.mm-search-ico { width: 22px; height: 22px; color: var(--pri, #1E40AF); flex-shrink: 0; }
.mm-search-input {
  flex: 1; min-width: 0; border: 0; outline: 0; font: 500 17px 'DM Sans', sans-serif; color: var(--n-900, #0F172A); background: transparent; height: 32px;
}
.mm-search-input::-webkit-search-cancel-button { display: none; }
.mm-search-x {
  border: 1px solid var(--n-200, #E2E8F0); border-radius: 7px; background: var(--n-50, #F8FAFC);
  font: 600 11px 'DM Sans', sans-serif; color: var(--n-500, #64748B); padding: 4px 8px; cursor: pointer;
}
.mm-search-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.mm-search-list { list-style: none; margin: 0; padding: 6px 8px 10px; overflow-y: auto; overscroll-behavior: contain; }
.mm-search-group {
  font: 700 10.5px 'DM Sans', sans-serif; letter-spacing: .09em; text-transform: uppercase; color: var(--n-500, #64748B);
  padding: 12px 10px 5px;
}
.mm-search-hit {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 11px; cursor: pointer;
  scroll-margin: 8px;
}
.mm-search-hit.on { background: var(--blue-bg, #E6F1FB); }
.mm-hit-ico {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0;
  background: var(--bg3, #F0F5FC); color: var(--navy-light, #185FA5);
}
.mm-hit-ico svg { width: 17px; height: 17px; }
.mm-hit-course { background: var(--teal-bg, #E1F5EE); color: var(--teal-dark, #0F6E56); }
.mm-hit-page { background: var(--amber-bg, #FAEEDA); color: var(--amber-dark, #854F0B); }
.mm-hit-c { background: var(--purple-bg, #EEEDFE); color: var(--purple, #534AB7); }
.mm-hit-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mm-hit-t { font: 500 14px/1.35 'DM Sans', sans-serif; color: var(--n-900, #0F172A); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.mm-hit-t mark { background: rgba(239, 159, 39, .28); color: inherit; border-radius: 3px; padding: 0 1px; }
.mm-hit-ref { font: 700 11px 'DM Sans', sans-serif; color: var(--pri, #1E40AF); background: var(--blue-bg, #E6F1FB); border-radius: 5px; padding: 1px 6px; margin-right: 7px; }
.mm-hit-s { font: 400 12px 'DM Sans', sans-serif; color: var(--n-500, #64748B); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.mm-hit-tags { display: flex; gap: 4px; flex-shrink: 0; }
.mm-tag { font: 600 10px 'DM Sans', sans-serif; border-radius: 999px; padding: 2px 7px; white-space: nowrap; }
.mm-tag-n { background: var(--teal-bg, #E1F5EE); color: var(--teal-dark, #0F6E56); }
.mm-tag-m { background: var(--purple-bg, #EEEDFE); color: var(--purple, #534AB7); }
.mm-hit-go { width: 16px; height: 16px; color: var(--n-500, #64748B); opacity: 0; flex-shrink: 0; }
.mm-search-hit.on .mm-hit-go { opacity: 1; color: var(--pri, #1E40AF); }

.mm-search-hint p, .mm-search-empty { margin: 0; padding: 18px 10px; color: var(--n-500, #64748B); font-size: 13px; line-height: 2; }
.mm-search-hint button {
  border: 1px solid var(--n-200, #E2E8F0); background: var(--n-50, #F8FAFC); border-radius: 999px;
  padding: 3px 11px; margin: 0 3px; font: 500 12px 'DM Sans', sans-serif; color: var(--n-700, #334155); cursor: pointer;
}
.mm-search-hint button:hover { border-color: var(--pri-accent, #2563EB); color: var(--pri, #1E40AF); }
.mm-search-empty { display: flex; flex-direction: column; line-height: 1.6; }
.mm-search-empty b { color: var(--n-900, #0F172A); font-weight: 600; }

.mm-search-foot {
  display: flex; gap: 16px; padding: 9px 16px; border-top: 1px solid var(--n-200, #E2E8F0); background: var(--n-50, #F8FAFC);
  font: 500 11px 'DM Sans', sans-serif; color: var(--n-500, #64748B);
}
.mm-search-foot kbd { font: 600 10px 'DM Sans', sans-serif; border: 1px solid var(--n-200, #E2E8F0); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: #fff; margin-right: 3px; }

@media (max-width: 600px) {
  .mm-search { padding: 0; }
  .mm-search-panel { max-width: none; max-height: none; height: 100%; border-radius: 0; }
  .mm-search-foot { display: none; }
  .mm-hit-tags { flex-direction: column; align-items: flex-end; gap: 3px; }
}

/* ── Row reached from a search result ─────────────────────────── */
.st-row.mm-hit-row { animation: mmHitRow 2.6s ease-out; }
@keyframes mmHitRow { 0%, 35% { background: rgba(239, 159, 39, .26); box-shadow: inset 3px 0 0 var(--amber-border, #EF9F27); } 100% { background: transparent; box-shadow: none; } }
@media (prefers-reduced-motion: reduce) { .st-row.mm-hit-row { animation: none; background: rgba(239, 159, 39, .2); } }
