/* ===== Phone and tablet optimisation =====
   Loaded last. Three concerns:
   1. Touch: tap targets of about 44px and 16px form text (stops iOS zoom on focus).
   2. Tablets: denser tables so key columns and actions stay on screen.
   3. Phones: data tables become stacked cards (ui.js adds the column labels). */

/* 1. Touch screens (phones, iPads, Android tablets) */
@media (pointer: coarse) {
  input, select, .multi-trigger { font-size: 16px; }
  .navigation a { min-height: 44px; }
  .header-source { display: inline-flex; align-items: center; min-height: 44px; }
  .header-udf { padding-block: 11px; }
  .button { min-height: 44px; }
  .icon-button { min-width: 44px; min-height: 44px; }
  .tab { min-height: 44px; }
  .page-size select { min-height: 44px; }
  .chip { min-height: 36px; }
  .chip span { width: 24px; height: 24px; }
  .multi-option { min-height: 46px; }
  .multi-option input { width: 20px; height: 20px; }
  .footer-links a { display: inline-flex; align-items: center; min-height: 40px; }
  .footer-social a { width: 44px; height: 44px; }
  .contact-value { min-height: 44px; display: inline-flex; align-items: center; }
  .seat-chip { width: 44px; height: 36px; }
  .to-top { width: 48px; height: 48px; }
  /* Hover lifts feel sticky on touch, so drop them. */
  .button:hover, .icon-button:hover:not(:disabled), .feature-card:hover, .contact-card:hover, .stat-strip > div:hover, .hero-stats div:hover { transform: none; }
}
@media (max-width: 1024px) {
  input, select, .multi-trigger { font-size: 16px; }
}

/* 2. Tablets: tighter tables */
@media (max-width: 1100px) {
  th, td { padding: 9px 8px; }
  th { white-space: normal; line-height: 1.25; }
  .college-cell { min-width: 108px; }
  .branch-cell { min-width: 118px; }
  .row-actions { gap: 4px; }
  .result-head h2 { font-size: 21px; }
  .filter-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
/* Tablets: when a wide table scrolls sideways, keep the Actions column pinned
   to the right edge so save and details are always reachable. */
@media (min-width: 621px) and (max-width: 1100px) {
  .cardify td.card-actions, .cardify thead th:last-child { position: sticky; right: 0; z-index: 1; background: var(--surface); box-shadow: -10px 0 10px -10px #13254b40; }
  .cardify thead th:last-child { background: #eef2f9; }
  .cardify tbody tr:hover td.card-actions { background: #f5f8fe; }
}

/* Predictor results switch to cards below 900px so actions never go off-screen. */
@media (max-width: 900px) {
  #prediction-table table, #prediction-table tbody { display: block; }
  #prediction-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #prediction-table tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px 14px; padding: 13px 14px; border-bottom: 1px solid var(--border); }
  #prediction-table tbody tr:last-child { border-bottom: 0; }
  #prediction-table td { display: block; padding: 0; border: 0; }
  #prediction-table .college-cell, #prediction-table .branch-cell { min-width: 0; }
  #prediction-table .prediction-institute { grid-column: 1; }
  #prediction-table .prediction-branch { grid-column: 2; }
  #prediction-table .prediction-actions { grid-column: 3; grid-row: 1 / span 2; }
  #prediction-table .prediction-grade { grid-column: 1; }
  #prediction-table .prediction-range { grid-column: 2; }
  #prediction-table .prediction-seats { grid-column: 1 / span 2; text-align: left; }
  #prediction-table [data-label]::before { content: attr(data-label); display: block; color: var(--muted); font-size: 11px; font-weight: 550; }
  .table-tools { flex-wrap: wrap; }
}
@media (max-width: 620px) {
  #prediction-table tbody tr { grid-template-columns: minmax(0, 1fr) auto; }
  #prediction-table .prediction-institute, #prediction-table .prediction-branch, #prediction-table .prediction-grade, #prediction-table .prediction-range, #prediction-table .prediction-seats { grid-column: 1; }
  #prediction-table .prediction-actions { grid-column: 2; grid-row: 1 / span 2; }
}

/* 3. Phones: every other data table becomes stacked cards */
@media (max-width: 620px) {
  .cardify table, .cardify tbody, .cardify tr, .cardify td { display: block; }
  .cardify table { min-width: 0; }
  .cardify thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .cardify tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 14px; padding: 13px 14px; border-bottom: 1px solid var(--border); }
  .cardify tbody tr:last-child { border-bottom: 0; }
  .cardify td { min-width: 0; padding: 0; border: 0; text-align: left; white-space: normal; }
  .cardify td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 1px; color: var(--muted); font-size: 11px; font-weight: 550; }
  .cardify td.card-wide { grid-column: 1 / -1; order: -1; }
  .cardify td.card-name { order: -2; }
  .cardify td.card-actions { order: 99; }
  .cardify td.card-name::before { display: none; }
  .cardify td.card-actions { grid-column: 1 / -1; }
  .cardify td.card-actions::before { display: none; }
  .cardify .row-actions { justify-content: start; }
  .cardify .college-cell b { font-size: 15px; }
  .cardify td.card-blank { display: none; }

  .stat-strip { gap: 8px; }
  .stat-strip > div { padding: 10px 12px; }
  .stat-strip strong { font-size: 18px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs-end { padding-left: 8px; }
  .pagination { justify-content: center; }
  .pagination > span { width: 100%; text-align: center; }
  .filter-panel { padding: 13px; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .details-dialog { width: 100%; max-width: none; max-height: 100%; height: 100%; margin: 0; border-radius: 0; }
  .dialog-inner { padding: 18px 16px 28px; }
  .dialog-inner h2 { font-size: 21px; }
  .subpage-heading h1 { font-size: 28px; }
  .hero h1 { font-size: 29px; }
  .hero-lede { font-size: 14px; }
  #predictor > .predict-form { margin-top: -40px; }
  .predict-button { min-height: 48px; font-size: 15px; }
  .matrix-grid { max-height: 65vh; }
  .matrix-grid .grid-branch { min-width: 120px; max-width: 140px; font-size: 11px; }
  .contact-card { padding: 18px; }
}

/* Very small phones (iPhone SE, 320-360px) */
@media (max-width: 360px) {
  .frame { width: calc(100% - 20px); }
  .filter-grid { grid-template-columns: 1fr; }
  .fields { grid-template-columns: 1fr; }
  .predict-button { grid-column: auto; }
  .brand-text small { display: none; }
  .hero-stats dd { font-size: 18px; }
}

/* iPad landscape and small laptops: keep the hero badge from crowding the copy */
@media (min-width: 901px) and (max-width: 1100px) {
  .hero-inner { grid-template-columns: minmax(0, 1fr) 230px; }
  .hero-badge { width: 230px; }
}
