/* ============================================================
   RankVision v2 — Predictor & Results CSS
   Fully mobile-responsive: 320px → 1440px
   ============================================================ */

/* ══════════════════════════════════════════════════════════ */
/*  PREDICTOR FORM                                            */
/* ══════════════════════════════════════════════════════════ */

.predictor-section {
  background: var(--bg-2);
}

.predictor-form-card {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  padding: clamp(1.25rem, 4vw, 2.25rem);
  max-width: 1000px;
  margin: 0 auto;
  box-shadow: var(--shadow-lg);
}

/* Form grids - collapse on mobile */
.form-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.form-grid-4 {
  grid-template-columns: 2fr 1fr 1fr 1fr;
}

.form-grid-2 {
  grid-template-columns: 1fr 1fr;
}

.rank-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.rank-icon {
  position: absolute;
  left: 14px;
  font-weight: 900;
  color: var(--text-muted);
  z-index: 1;
  font-size: 1rem;
}

.rank-input-wrapper .form-input {
  padding-left: 30px;
  font-size: 1.05rem;
  font-weight: 600;
}

.rank-input-wrapper .form-input::-webkit-inner-spin-button,
.rank-input-wrapper .form-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

/* Select2 overrides */
.select2-container--default .select2-selection--multiple,
.select2-container--default .select2-selection--single {
  background: var(--bg-3) !important;
  border: 1px solid var(--border-2) !important;
  border-radius: var(--r-md) !important;
  min-height: 44px !important;
  color: var(--text) !important;
}

.select2-container--default .select2-selection--multiple {
  padding: 4px 8px !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  color: var(--text) !important;
  padding: 8px 12px !important;
  line-height: 1.4 !important;
}

.select2-container--default .select2-results__option {
  background: var(--bg-3) !important;
  color: var(--text) !important;
  font-size: 0.875rem;
}

.select2-container--default .select2-results__option--highlighted {
  background: var(--bg-4) !important;
  color: var(--primary) !important;
}

.select2-dropdown {
  background: var(--bg-2) !important;
  border: 1px solid var(--border-2) !important;
  border-radius: var(--r-md) !important;
}

.select2-search--dropdown .select2-search__field {
  background: var(--bg-3) !important;
  border: 1px solid var(--border-2) !important;
  color: var(--text) !important;
  border-radius: 6px !important;
  padding: 5px 10px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice {
  background: var(--primary) !important;
  border: none !important;
  border-radius: 6px !important;
  color: #fff !important;
  font-size: 0.78rem !important;
  padding: 2px 8px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
  color: rgba(255, 255, 255, 0.7) !important;
}

.select2-container {
  width: 100% !important;
}

/* Round Chips */
.rounds-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding-top: 2px;
}

.round-chip {
  padding: 0.4rem 0.85rem;
  border-radius: var(--r-full);
  border: 1px solid var(--border-2);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  background: var(--bg-4);
}

.round-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.round-chip.selected {
  background: var(--text);
  color: var(--bg-0);
  border-color: var(--text);
}

/* Predict Button */
#predict-btn {
  border-radius: var(--r-md) !important;
  height: 52px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  position: relative;
  overflow: hidden;
}

#predict-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.12), transparent);
  transform: translateX(-100%);
  transition: transform 0.5s;
}

#predict-btn:hover::after {
  transform: translateX(100%);
}

#predict-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ══════════════════════════════════════════════════════════ */
/*  RESULTS                                                    */
/* ══════════════════════════════════════════════════════════ */

.results-section {
  padding: 2rem 0 4rem;
}

/* Summary Pills */
.summary-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.summary-pill {
  padding: 0.35rem 0.85rem;
  border-radius: var(--r-full);
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.pill-safe {
  background: rgba(34, 197, 94, 0.12);
  color: var(--safe);
  border-color: rgba(34, 197, 94, 0.25);
}

.pill-moderate {
  background: rgba(245, 158, 11, 0.12);
  color: var(--moderate);
  border-color: rgba(245, 158, 11, 0.25);
}

.pill-dream {
  background: rgba(239, 68, 68, 0.12);
  color: var(--dream);
  border-color: rgba(239, 68, 68, 0.25);
}

/* Toolbar */
.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.results-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.results-count strong {
  color: var(--text);
}

.results-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Filter Bar */
.results-filter-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
  padding: 0.6rem 1rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
}

.filter-chip {
  padding: 0.3rem 0.85rem;
  border-radius: var(--r-full);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.15s;
}

.filter-chip:hover {
  color: var(--text);
}

.filter-chip.active {
  background: var(--text);
  color: var(--bg-0);
}

.filter-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
}

.sort-select {
  background: #001015;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
}

.sort-select:focus {
  outline: none;
  border-radius: 6px;
}

/* Search Bar */
.results-search-bar {
  position: relative;
  margin-bottom: 1.25rem;
}

.results-search-bar .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.results-search-bar input {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--r-full);
  padding: 0.65rem 1rem 0.65rem 2.75rem;
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

.results-search-bar input:focus {
  border-color: var(--primary);
}

/* Institute Cards */
.inst-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: 0.75rem;
  overflow: hidden;
  transition: border-color 0.2s;
}

.inst-card:hover {
  border-color: var(--border-2);
}

.inst-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  cursor: pointer;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.inst-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.inst-badge {
  padding: 3px 10px;
  border-radius: var(--r-sm);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.badge-IIT {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
}

.badge-NIT {
  background: rgba(129, 140, 248, 0.15);
  color: #818cf8;
}

.badge-IIIT {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.badge-GFTI {
  background: rgba(107, 114, 128, 0.15);
  color: #9ca3af;
}

.inst-name {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

@media (max-width: 480px) {
  .inst-name {
    font-size: 0.85rem;
    white-space: normal;
  }
}

.inst-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.inst-card-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.heatmap-strip {
  width: 60px;
  height: 6px;
  background: var(--bg-4);
  border-radius: 3px;
  overflow: hidden;
}

.heatmap-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}

.heatmap-safe,
.heatmap-safe-high {
  background: linear-gradient(90deg, #16a34a, #22c55e);
}

.heatmap-moderate {
  background: linear-gradient(90deg, #b45309, #f59e0b);
}

.heatmap-dream {
  background: linear-gradient(90deg, #b91c1c, #ef4444);
}

.heatmap-mixed {
  background: linear-gradient(90deg, #22c55e 33%, #f59e0b 66%, #ef4444);
}

@media (max-width: 480px) {
  .heatmap-strip {
    display: none;
  }
}

.inst-score {
  font-weight: 900;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.score-safe-high {
  color: #4ade80;
}

.score-safe {
  color: #22c55e;
}

.score-moderate {
  color: #f59e0b;
}

.score-dream {
  color: #ef4444;
}

.toggle-icon {
  color: var(--text-muted);
  font-size: 0.7rem;
  transform: rotate(-90deg);
  transition: transform 0.2s;
}

.inst-card.expanded .toggle-icon {
  transform: rotate(0deg);
}

/* Branches table */
.branches-container {
  display: flex;
  border-top: 1px solid var(--border);
  overflow-x: auto;
}

.inst-card.expanded .branches-container {
  display: block;
}

.branches-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  min-width: 680px;
}

.branches-table th {
  background: var(--bg-3);
  padding: 0.6rem 0.85rem;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.branches-table td {
  padding: 0.6rem 0.85rem;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

.branches-table tr:hover td {
  background: var(--bg-3);
}

.branch-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}

.branch-name {
  font-weight: 600;
  color: var(--text);
}

.rank-range {
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.prob-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.prob-mini {
  font-size: 0.78rem;
  font-weight: 800;
  min-width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.prob-track {
  width: 70px;
  height: 5px;
  background: var(--bg-4);
  border-radius: 3px;
  flex-shrink: 0;
}

.prob-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 1s ease;
}

.zone-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.zone-safe-high {
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
}

.zone-safe {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.zone-moderate {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.zone-dream {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.bookmark-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 0.8rem;
  transition: all 0.15s;
  color: var(--text-muted);
}

.bookmark-btn:hover,
.bookmark-btn.saved {
  background: var(--bg-4);
  color: var(--text);
  border-color: var(--border-2);
}

/* JoSAA Simulator Row */
.simulator-row {
  background: var(--bg-3);
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
}

.simulator-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.round-sims {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.round-sim-chip {
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid var(--border-2);
  background: var(--bg-4);
  white-space: nowrap;
}

.round-sim-chip.sim-high {
  border-color: rgba(34, 197, 94, 0.4);
  background: rgba(34, 197, 94, 0.08);
  color: #22c55e;
}

.round-sim-chip.sim-medium {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.08);
  color: #f59e0b;
}

.round-sim-chip.sim-low {
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.08);
  color: #ef4444;
}

/* No Results */
.no-results {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}

.no-results .icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.no-results h3 {
  margin-bottom: 0.5rem;
  color: var(--text);
}

/* Skeleton */
.skeleton-card {
  height: 72px;
  background: linear-gradient(90deg, var(--bg-3) 25%, var(--bg-4) 50%, var(--bg-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-lg);
  margin-bottom: 0.75rem;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

/* ══════════════════════════════════════════════════════════ */
/*  RANK RANGE EXPLORER                                        */
/* ══════════════════════════════════════════════════════════ */
.range-results {
  margin-top: 1rem;
  max-height: 360px;
  overflow-y: auto;
}

.range-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.range-result-item:last-child {
  border-bottom: none;
}

.range-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg-4);
}

/* ══════════════════════════════════════════════════════════ */
/*  MOBILE RESPONSIVE PATCHES                                  */
/* ══════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .form-grid-4 {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid-2 {
    grid-template-columns: 1fr;
  }

  .predictor-form-card {
    padding: 1.25rem;
    border-radius: var(--r-lg);
  }

  .results-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .results-actions {
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .results-filter-bar {
    border-radius: var(--r-lg);
    overflow-x: auto;
  }

  .results-filter-bar::-webkit-scrollbar {
    display: none;
  }

  .inst-card-header {
    padding: 0.85rem;
  }

  .inst-score {
    font-size: 0.9rem;
  }

  .compare-bar .container {
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
  }

  #compare-list {
    flex-wrap: wrap;
  }
}

/* Small mobile: stack rank row */
@media (max-width: 480px) {
  .form-grid-4 {
    grid-template-columns: 1fr;
  }

  .round-sims {
    gap: 0.3rem;
  }

  .summary-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .summary-pills::-webkit-scrollbar {
    display: none;
  }
}

/* Tablet specific */
@media (min-width: 600px) and (max-width: 767px) {
  .form-grid-4 {
    grid-template-columns: 1fr 1fr;
  }
}

/* ══════════════════════════════════════════════════════════ */
/*  ADVANCED FILTER PANEL                                      */
/* ══════════════════════════════════════════════════════════ */

#adv-filter-panel {
  right: -420px;
  transition: right 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

#adv-filter-panel.open {
  right: 0 !important;
}

.adv-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.85rem;
  border-radius: var(--r-full);
  border: 1px solid var(--border-2);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  background: var(--bg-4);
  color: var(--text-muted);
  transition: all 0.15s;
  white-space: nowrap;
}

.adv-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.adv-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

[data-theme="light"] .adv-chip.active {
  color: #0f172a;
}

/* Advanced filter badge */
#adv-filter-badge {
  display: none;
  position: absolute;
  top: -7px;
  right: -7px;
  background: #ef4444;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-1);
}

/* ══════════════════════════════════════════════════════════ */
/*  BRANCH TABLE EXTRAS                                        */
/* ══════════════════════════════════════════════════════════ */

.cutoff-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.cutoff-open {
  color: var(--safe);
  font-weight: 600;
  font-size: 0.82rem;
}

.cutoff-arrow {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.cutoff-close {
  color: var(--dream);
  font-weight: 700;
  font-size: 0.85rem;
}

.demand-tag {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  background: var(--bg-4);
  color: var(--text-muted);
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
}

.prestige-tag {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-left: 6px;
}

.col-center {
  text-align: center;
}

.action-btns {
  display: flex;
  gap: 4px;
  align-items: center;
}

/* ══════════════════════════════════════════════════════════ */
/*  PWA INSTALL PROMPT                                         */
/* ══════════════════════════════════════════════════════════ */

#install-prompt {
  position: fixed;
  bottom: 5rem;
  right: 1.5rem;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  padding: 1rem 1.25rem;
  z-index: 85;
  max-width: 300px;
  box-shadow: var(--shadow-lg);
  display: none;
  gap: 0.75rem;
  flex-direction: column;
}

#install-prompt.show {
  display: flex;
}

#install-prompt p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

/* ══════════════════════════════════════════════════════════ */
/*  RESPONSIVE BREAKPOINTS                                     */
/* ══════════════════════════════════════════════════════════ */

/* ── Tablet (≤ 900px): Form 4-col → 2-col ─────────────── */
@media (max-width: 900px) {
  .form-grid-4 {
    grid-template-columns: 1fr 1fr;
  }
}

/* ── Tablet narrow (≤ 700px): 2-col → 1-col ──────────── */
@media (max-width: 700px) {
  .form-grid-4 {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid-2 {
    grid-template-columns: 1fr;
  }

  .predictor-form-card {
    padding: 1.25rem;
  }

  /* Results table becomes scrollable */
  .results-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .results-table {
    min-width: 700px;
  }

  /* Analytics cards: 2 per row on tablet */
  .analytics-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Toolbar wraps on mobile */
  .results-toolbar {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .results-toolbar .toolbar-right {
    flex-wrap: wrap;
  }
}

/* ── Mobile (≤ 500px): single column everything ─────── */
@media (max-width: 500px) {
  .form-grid-4 {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid-2,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .analytics-grid {
    grid-template-columns: 1fr;
  }

  .results-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .results-toolbar>* {
    width: 100%;
    justify-content: center;
  }

  .summary-pills {
    flex-wrap: wrap;
    gap: 0.3rem;
  }

  .rounds-chips {
    flex-wrap: wrap;
  }

  /* Larger touch targets */
  .form-select,
  .form-input {
    min-height: 44px;
    font-size: 1rem;
  }

  .chip {
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
  }
}

/* ── Very small phones (≤ 380px) ───────────────────── */
@media (max-width: 380px) {
  .section-header h2 {
    font-size: 1.25rem;
  }

  #predict-btn {
    font-size: 0.9rem;
  }
}