/* Mobile-first overrides. Loaded after role styles to keep desktop behavior intact. */
.parent-tab-bar { display: none; }
.mobile-logout-button { display: none; }

@media (max-width: 760px) {
  :root { --mobile-nav-height: 72px; }

  html { background: var(--soft); }
  body { min-height: 100dvh; }

  body.role-student .app-shell,
  body.role-parent .app-shell {
    display: block;
    min-height: 100dvh;
    height: auto;
    overflow: visible;
  }

  body.role-student .sidebar,
  body.role-parent .sidebar {
    display: none !important;
  }

  body.role-student .student-tab-bar,
  body.role-parent .parent-tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 700;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    min-height: var(--mobile-nav-height);
    padding: 6px max(6px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(16px);
  }

  body.role-parent .parent-tab-bar {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .student-tab-bar.hidden,
  .parent-tab-bar.hidden { display: none !important; }

  .tab-item {
    min-width: 0;
    min-height: 52px;
    padding: 5px 2px;
    border-radius: 8px;
    gap: 2px;
    font-size: 10px;
  }

  .tab-icon { font-size: 19px; }
  body.role-parent .tab-item.active { color: var(--parent-primary); }

  body.role-student .main-content,
  body.role-parent .main-content {
    display: grid;
    gap: 16px;
    width: 100%;
    max-width: none;
    min-height: 100dvh;
    max-height: none;
    margin: 0;
    padding: 0 12px calc(var(--mobile-nav-height) + 22px + env(safe-area-inset-bottom));
    overflow: visible;
    scrollbar-gutter: auto;
  }

  body.role-student .topbar,
  body.role-parent .topbar {
    position: sticky;
    top: 0;
    z-index: 300;
    width: calc(100% + 24px);
    min-height: 58px;
    margin: 0 -12px;
    padding: 9px 14px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 5px 18px rgba(15, 23, 42, 0.05);
    backdrop-filter: blur(14px);
  }

  body.role-student .topbar .eyebrow,
  body.role-parent .topbar .eyebrow { display: none; }

  body.role-student .topbar h2,
  body.role-parent .topbar h2 {
    font-size: 20px;
    line-height: 1.2;
  }

  .score-box {
    min-height: 40px;
    padding: 6px 10px;
    gap: 5px;
    border-radius: 8px;
  }

  .score-box .score-label { display: none; }
  .score-box strong { font-size: 18px; }
  body.role-parent .score-box { display: none; }

  .mobile-logout-button {
    width: 44px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    color: var(--text-secondary);
    background: #fff;
    font-size: 12px;
    font-weight: 700;
  }

  .view.is-visible {
    width: 100% !important;
    min-width: 0;
    margin: 0 !important;
  }

  .section-head {
    flex-direction: row;
    align-items: flex-end;
    gap: 10px;
  }

  .section-head h3 { font-size: 20px; }
  .section-head p { font-size: 12px; line-height: 1.45; }
  .section-head > .primary-button {
    min-height: 42px;
    padding: 0 13px;
    flex-shrink: 0;
    font-size: 12px;
  }

  .compact-field {
    width: 118px;
    flex-shrink: 0;
  }

  .compact-field select { min-height: 40px; width: 100%; }

  .filter-bar {
    flex-wrap: nowrap;
    gap: 8px;
    padding-bottom: 2px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .filter-bar::-webkit-scrollbar { display: none; }
  .filter-chip {
    min-height: 40px;
    padding: 7px 15px;
    flex: 0 0 auto;
  }

  .kpi-grid,
  body.role-student .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  body.role-student .kpi-card:first-child { grid-column: 1 / -1; }
  body.role-student .kpi-card,
  body.role-parent .kpi-card {
    min-height: 108px;
    padding: 16px;
    border-radius: 12px;
  }

  body.role-student .kpi-card:first-child { min-height: 120px; }
  body.role-student .kpi-value,
  body.role-parent .kpi-value { font-size: 29px; }

  .plan-list,
  .prize-list { grid-template-columns: 1fr; gap: 10px; }

  body.role-student .card {
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 11px;
    min-height: 0;
    padding: 15px 14px 15px 18px;
    border-radius: 12px;
  }

  body.role-student .card::before { border-radius: 12px 0 0 12px; }
  body.role-student .card .card-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    font-size: 21px;
  }

  body.role-student .card .card-head { min-width: 0; }
  body.role-student .card .card-head strong { font-size: 15px; }
  body.role-student .card .meta-row { gap: 6px; }
  body.role-student .card .card-status,
  body.role-student .card .card-actions {
    grid-column: 2;
    justify-self: stretch;
  }

  body.role-student .card .card-status { justify-self: start; }
  body.role-student .card .card-actions {
    min-width: 0;
    justify-content: flex-start;
  }

  body.role-student .card .plan-action {
    min-height: 44px;
    padding: 0 16px;
  }

  body.role-parent .card,
  .prize-card {
    padding: 16px;
    border-radius: 10px;
  }

  .plan-approval-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .plan-approval-actions { justify-content: flex-end; }
  .plan-approval-actions button { min-height: 44px; }

  .family-panel { padding: 15px; border-radius: 10px; }
  .family-panel__summary { align-items: flex-start; }
  .family-invite-code strong { font-size: 16px; }
  .family-member-list { grid-template-columns: 1fr; }
  .family-member-item { grid-template-columns: 36px minmax(0, 1fr) auto; }
  .join-family-form { grid-template-columns: 1fr; }
  .join-family-form input,
  .join-family-form button { min-height: 46px; font-size: 16px; }
  .family-request-item { align-items: stretch; flex-direction: column; }
  .family-request-actions { justify-content: flex-end; }
  .family-request-actions button { min-height: 44px; }

  .score-hero { gap: 18px; }
  .score-hero__balance { padding: 15px 18px; }
  .lottery-wheel { width: min(78vw, 300px); height: min(78vw, 300px); }
  .lottery-btn { min-height: 48px; }

  .chart-area canvas { max-width: 100%; }

  #planForm:not(.hidden),
  #accountForm:not(.hidden) {
    position: fixed;
    inset: 0;
    z-index: 850;
    display: block;
    margin: 0;
    padding: calc(22px + env(safe-area-inset-top)) 18px calc(20px + env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
    overflow-y: auto;
    background: #fff;
  }

  #planForm .form-grid,
  #accountForm .form-grid { gap: 15px; }

  #planForm input,
  #planForm select,
  #planForm textarea,
  #accountForm input,
  #accountForm select { min-height: 48px; font-size: 16px; }

  #planForm .form-actions,
  #accountForm .form-actions {
    position: sticky;
    bottom: 0;
    margin: 22px -18px -20px;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--line);
  }

  #planForm .form-actions button,
  #accountForm .form-actions button { min-height: 46px; flex: 1; }

  .modal-overlay {
    align-items: end;
    padding-top: env(safe-area-inset-top);
  }

  .modal,
  body.role-student .completion-modal {
    width: 100%;
    max-height: 88dvh;
    padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0;
    overflow-y: auto;
  }

  .modal .form-actions button { min-height: 46px; }
  .completion-photo-placeholder {
    align-items: stretch;
    flex-direction: column;
  }
  body.role-student .completion-photo-actions { justify-content: stretch; }
  body.role-student .completion-photo-actions button { flex: 1; min-height: 44px; }

  .toast {
    left: 12px;
    right: 12px;
    bottom: calc(var(--mobile-nav-height) + 12px + env(safe-area-inset-bottom));
    width: auto;
    text-align: center;
  }

  .auth-screen { padding: 18px; min-height: 100dvh; }
  .auth-card { width: 100%; padding: 24px 20px; border-radius: 14px; }
  .auth-form input,
  .auth-form button { min-height: 48px; font-size: 16px; }
}

@media (max-width: 380px) {
  .section-head { align-items: flex-start; flex-direction: column; }
  .section-head > .primary-button { width: 100%; }
  .compact-field { width: 100%; }
  body.role-student .card .card-actions { flex-direction: column; align-items: stretch; }
}

@media (display-mode: standalone) and (max-width: 760px) {
  body.role-student .topbar,
  body.role-parent .topbar { padding-top: calc(9px + env(safe-area-inset-top)); }
}
