/* Mobile optimization — touch, performance, layout */

/* ── Performance ── */
@media (max-width: 768px) {
  main {
    animation: none;
  }

  .site-header,
  .school690-rating-card,
  .card,
  .news-card,
  .top-10-item {
    backdrop-filter: none !important;
  }

  .school690-table tbody tr.school690-row-enter,
  .school690-rating-card.is-entering,
  .school690-score.is-updating {
    animation: none !important;
  }

  .card:hover,
  .dashboard-card:hover,
  .news-card:hover,
  .top-10-item:hover,
  .task-card:hover {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Header & navigation ── */
@media (max-width: 768px) {
  .main-nav {
    display: none !important;
  }

  .header-primary {
    flex: 0 1 auto;
    min-width: 0;
  }

  .header-secondary {
    flex: 1;
    justify-content: flex-end;
    min-width: 0;
    overflow: visible;
  }

  .site-header,
  .site-header .container {
    overflow: visible;
  }

  .hamburger-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 4, 10, 0.55);
    z-index: 1090;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
  }

  .hamburger-backdrop.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .hamburger-dropdown {
    position: fixed;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    margin-top: 0;
    border-radius: 0 0 16px 16px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 1100;
    transform: translateY(-12px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
  }

  .hamburger-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
  }

  .hamburger-menu-content {
    padding: 1rem 1rem 1.25rem;
  }

  .hamburger-menu-heading {
    margin: 0 0 0.65rem;
    padding-bottom: 0.45rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--sk-red, #e31e24);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }

  .hamburger-menu-list a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  body.menu-open {
    overflow: hidden;
  }

  .hamburger-menu {
    display: flex !important;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
  }

  #logoutBtn,
  .header-secondary .btn-outline {
    min-height: 44px;
    padding: 0.5rem 0.85rem;
    font-size: 0.85rem;
  }

  .auth-actions {
    flex-direction: row !important;
    width: auto !important;
    gap: 0.4rem !important;
  }

  .auth-actions .btn {
    width: auto !important;
    min-height: 44px;
    padding: 0.5rem 0.75rem !important;
    font-size: 0.82rem !important;
  }
}

@media (max-width: 400px) {
  #logoutBtn {
    font-size: 0;
    padding: 0.5rem 0.65rem;
    min-width: 44px;
  }

  #logoutBtn::before {
    content: "⎋";
    font-size: 1.1rem;
  }
}

/* ── Touch targets ── */
@media (max-width: 768px) {
  .rating-tab,
  .achievement-tab,
  .auth-tab,
  .category-tab,
  .period-btn,
  .school690-filter-pill,
  .calendar-nav-btn,
  .btn {
    min-height: 44px;
  }

  .form-control,
  .filter-select,
  .auth-form input,
  .auth-form select {
    font-size: 16px;
    min-height: 44px;
  }
}

/* ── Ratings page ── */
@media (max-width: 768px) {
  .ratings-page h1 {
    font-size: 1.5rem;
  }

  .ratings-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-bottom: none;
    padding-bottom: 2px;
  }

  .ratings-tabs::-webkit-scrollbar {
    display: none;
  }

  .rating-tab {
    flex-shrink: 0;
    bottom: 0;
    border-bottom: none;
    border-radius: 8px;
    padding: 0.65rem 1rem;
  }

  .rating-tab.active {
    border-bottom: none;
  }

  .top-10-item {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 0.15rem 0.65rem;
    padding: 0.85rem 1rem;
  }

  .top-10-position {
    grid-row: 1 / 3;
    grid-column: 1;
    font-size: 1.15rem;
    min-width: 36px;
  }

  .top-10-icon {
    display: none;
  }

  .top-10-info {
    grid-column: 2;
    grid-row: 1 / 3;
    min-width: 0;
  }

  .top-10-name {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .top-10-belt {
    font-size: 0.72rem;
  }

  .top-10-points {
    grid-column: 3;
    grid-row: 1 / 3;
    text-align: right;
  }

  .top-10-points-value {
    font-size: 1.15rem;
  }

  .top-10-points-label {
    font-size: 0.72rem;
  }

  .user-position-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    gap: 0.25rem 0.65rem;
    align-items: center;
  }

  .user-position-label {
    grid-column: 1 / -1;
    font-size: 0.8rem;
  }

  .user-position-value {
    grid-row: 2;
    font-size: 1.1rem;
    min-width: 40px;
  }

  .user-position-info {
    grid-row: 2;
    min-width: 0;
  }

  .user-position-points {
    grid-row: 2;
  }

  /* School 690 table — keep table layout, horizontal scroll */
  .school690-table-wrap {
    margin: 0 -0.25rem;
    padding-bottom: 0.25rem;
  }

  .school690-table {
    min-width: 520px;
  }

  .school690-table thead {
    display: table-header-group;
  }

  .school690-table tbody {
    display: table-row-group;
  }

  .school690-table tr {
    display: table-row;
    margin-bottom: 0;
    border: none;
    border-radius: 0;
    padding: 0;
    background: transparent;
  }

  .school690-table td {
    display: table-cell;
    text-align: inherit;
    float: none;
  }

  .school690-table td::before {
    content: none !important;
  }

  .school690-months,
  .school690-divisions {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .school690-months::-webkit-scrollbar,
  .school690-divisions::-webkit-scrollbar {
    display: none;
  }

  .school690-filter-pill {
    flex-shrink: 0;
  }
}

/* ── Dashboard ── */
@media (max-width: 768px) {
  .dashboard h1 {
    font-size: 1.45rem;
  }

  .athlete-overview {
    grid-template-columns: 1fr;
  }

  .profile-card {
    flex-direction: column;
    text-align: center;
    align-items: center;
  }

  .profile-info h2 {
    font-size: 1.15rem;
  }

  .profile-tags {
    justify-content: center;
  }

  .analytics-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }

  .chart-container {
    height: 220px;
  }

  .dashboard-analytics h2 {
    font-size: 1.35rem;
  }

  .analytics-header {
    flex-direction: column;
    align-items: stretch;
  }

  .analytics-period-selector {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .period-btn {
    flex-shrink: 0;
  }
}

/* ── Calendar ── */
@media (max-width: 768px) {
  .calendar-layout {
    grid-template-columns: 1fr;
  }

  .calendar-header-title h2 {
    font-size: 1.35rem;
  }

  .calendar-weekdays,
  .calendar-grid {
    font-size: 0.82rem;
  }

  .calendar-day {
    min-height: 88px;
    padding: 0.45rem;
  }

  .calendar-event {
    font-size: 0.72rem;
    padding: 0.2rem 0.35rem;
  }

  .event-card-large {
    flex-direction: column;
  }

  .event-image-large {
    width: 100%;
    min-width: 100%;
    height: 180px;
  }
}

/* ── Profile, news, achievements ── */
@media (max-width: 768px) {
  .profile-header {
    padding: 1.25rem;
  }

  .profile-avatar-large {
    width: 88px;
    height: 88px;
    font-size: 1.75rem;
  }

  .profile-content {
    grid-template-columns: 1fr;
  }

  .news-header h1,
  .achievements-header h1,
  .events-header h1,
  .help-header h1,
  .tasks-header h1 {
    font-size: 1.65rem;
  }

  .news-image {
    height: 180px;
  }

  .achievements-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .achievement-tab {
    flex-shrink: 0;
  }

  .auth-page {
    padding: 2rem 0;
  }

  .auth-card {
    padding: 1.25rem;
  }
}

/* ── Footer compact ── */
@media (max-width: 768px) {
  .site-footer {
    margin-top: 2rem;
  }

  .footer-top {
    padding: 2rem 0;
    gap: 1.5rem;
  }

  .brand-stats {
    flex-direction: row;
    gap: 0.75rem;
  }

  .brand-stats div {
    padding: 0.75rem;
  }
}
