/* Self-contained stepped school picker (province -> district -> zone -> school).
   Namespaced .sp-* so it does not clash with Bootstrap/Tailwind on host pages. */

.sp-wrapper { position: relative; width: 100%; }

/* Institute / School toggle (career test, guest mode) */
.sp-toggle {
    display: inline-flex; padding: 3px; margin-bottom: 12px;
    background: #f1f3f5; border-radius: 10px;
}
.sp-toggle-btn {
    padding: 7px 20px; border: none; background: transparent; color: #4b5563;
    cursor: pointer; font-size: 14px; font-weight: 500; border-radius: 8px; transition: all .15s ease;
}
.sp-toggle-btn.is-active { background: #fff; color: #2563eb; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.dark .sp-toggle { background: #1f2937; }
.dark .sp-toggle-btn { color: #9ca3af; }
.dark .sp-toggle-btn.is-active { background: #111827; color: #60a5fa; }

/* Trigger (looks like a form input) */
.sp-trigger {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    width: 100%; min-height: 44px; padding: 10px 14px;
    border: 1px solid #d1d5db; border-radius: 10px; background: #fff;
    color: #111827; font-size: 14px; line-height: 1.3; text-align: left;
    cursor: pointer; transition: border-color .15s ease, box-shadow .15s ease;
}
.sp-trigger:hover { border-color: #9ca3af; }
.sp-trigger:focus-visible { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.18); }
.sp-trigger-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-trigger.is-placeholder .sp-trigger-label { color: #9ca3af; }
.sp-trigger-caret { flex-shrink: 0; width: 18px; height: 18px; opacity: .5; }
.sp-wrapper.is-disabled .sp-trigger { background: #f3f4f6; cursor: not-allowed; opacity: .7; }

/* Modal */
.sp-modal { position: fixed; inset: 0; z-index: 100000; display: flex; align-items: center; justify-content: center; }
.sp-modal[hidden] { display: none; }
.sp-backdrop {
    position: absolute; inset: 0; background: rgba(17,24,39,.5);
    backdrop-filter: blur(2px); animation: sp-fade .18s ease;
}
.sp-panel {
    position: relative; display: flex; flex-direction: column;
    width: 100%; max-width: 440px; max-height: 84vh; margin: 16px;
    background: #fff; border-radius: 18px; overflow: hidden;
    box-shadow: 0 24px 60px rgba(0,0,0,.28); animation: sp-pop .2s cubic-bezier(.2,.8,.3,1);
}
@keyframes sp-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes sp-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

.sp-header {
    position: sticky; top: 0; z-index: 1;
    display: flex; align-items: center; gap: 8px;
    padding: 14px 14px;
    background: var(--primary, #4984F6);
    border-bottom: none;
}
.sp-back, .sp-close {
    flex: 0 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border: none; background: rgba(255,255,255,.18);
    border-radius: 50%; cursor: pointer; color: #fff; font-size: 18px; line-height: 1;
    transition: background .15s ease;
}
.sp-back:hover, .sp-close:hover { background: rgba(255,255,255,.32); color: #fff; }
/* Keep the back slot occupied when hidden so the title stays centred. */
.sp-back[hidden] { display: inline-flex; visibility: hidden; }
.sp-title {
    flex: 1; min-width: 0; text-align: center; padding: 0 2px;
    font-weight: 500; font-size: 16px; color: #fff; letter-spacing: -.01em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.sp-breadcrumb { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px 0; }
.sp-breadcrumb:empty { display: none; }
.sp-breadcrumb span {
    display: inline-flex; align-items: center; padding: 3px 10px;
    background: #eef2ff; color: #4338ca; font-size: 12px; font-weight: 500; border-radius: 999px;
}

.sp-search { padding: 12px 16px 4px; }
.sp-search[hidden] { display: none; }
.sp-search input {
    width: 100%; padding: 10px 14px; border: 1px solid #e5e7eb; border-radius: 10px;
    font-size: 14px; background: #f9fafb; transition: all .15s ease;
}
.sp-search input:focus { outline: none; border-color: #2563eb; background: #fff; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }

.sp-list { flex: 1; overflow-y: auto; margin: 0; padding: 8px; list-style: none; }
.sp-list li {
    position: relative; display: flex; align-items: center;
    padding: 12px 40px 12px 14px; border-radius: 10px; cursor: pointer;
    font-size: 14px; color: #1f2937; transition: background .12s ease;
}
.sp-list li:hover { background: #f3f4f6; }
.sp-list li:active { background: #e5e7eb; }
.sp-list li.is-selected { background: #eff6ff; color: #1d4ed8; font-weight: 600; }
/* Drill-down steps (province/district/zone) get a right chevron. */
.sp-list--drill li::after {
    content: ""; position: absolute; right: 16px; top: 50%;
    width: 8px; height: 8px; border-right: 2px solid #9ca3af; border-bottom: 2px solid #9ca3af;
    transform: translateY(-50%) rotate(-45deg);
}
/* Selected school shows a check instead. */
.sp-list:not(.sp-list--drill) li.is-selected::after {
    content: "✓"; position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
    color: #2563eb; font-weight: 700;
}

.sp-state { padding: 40px 16px; text-align: center; color: #9ca3af; font-size: 14px; }
.sp-state[hidden] { display: none; }
.sp-loading::before {
    content: ""; display: block; width: 26px; height: 26px; margin: 0 auto 12px;
    border: 3px solid #e5e7eb; border-top-color: #2563eb; border-radius: 50%;
    animation: sp-spin .7s linear infinite;
}
@keyframes sp-spin { to { transform: rotate(360deg); } }

/* Bottom-sheet on small screens */
@media (max-width: 480px) {
    .sp-modal { align-items: flex-end; }
    .sp-panel {
        max-width: 100%; margin: 0; max-height: 88vh;
        border-radius: 20px 20px 0 0; animation: sp-sheet .24s cubic-bezier(.2,.8,.3,1);
    }
    @keyframes sp-sheet { from { transform: translateY(100%); } to { transform: none; } }
}

/* Dark mode */
.dark .sp-trigger { background: #1f2937; border-color: #374151; color: #e5e7eb; }
.dark .sp-panel { background: #111827; color: #e5e7eb; }
.dark .sp-header { background: var(--primary, #4984F6); border-color: transparent; }
.dark .sp-title { color: #fff; }
.dark .sp-back, .dark .sp-close { background: rgba(255,255,255,.18); color: #fff; }
.dark .sp-back:hover, .dark .sp-close:hover { background: rgba(255,255,255,.32); color: #fff; }
.dark .sp-breadcrumb span { background: #1e293b; color: #93c5fd; }
.dark .sp-search input { background: #1f2937; border-color: #374151; color: #e5e7eb; }
.dark .sp-search input:focus { background: #111827; }
.dark .sp-list li { color: #e5e7eb; }
.dark .sp-list li:hover { background: #1f2937; }
.dark .sp-list li.is-selected { background: #1e3a8a33; color: #93c5fd; }
