html,
body,
.app-shell,
.main,
.view,
.panel,
.topbar,
.sidebar,
.dashboard-summary-panel,
.dashboard-workspace-grid,
.dashboard-analysis-layout,
.dashboard-bottom-grid,
.content-grid,
.split-layout,
.team-grid {
  min-width: 0;
}

.view.active {
  grid-template-columns: minmax(0, 1fr);
}

.view > *,
.panel > *,
.dashboard-summary-panel > *,
.dashboard-workspace-grid > *,
.dashboard-analysis-layout > *,
.dashboard-bottom-grid > *,
.content-grid > *,
.split-layout > *,
.team-grid > * {
  min-width: 0;
}

img,
svg,
canvas,
video {
  max-width: 100%;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
    gap: 12px;
    box-shadow: none;
  }

  .nav-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-height: 260px;
    overflow-y: auto;
    padding-right: 2px;
  }

  .nav-tab {
    justify-content: center;
  }

  .sidebar-footer {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric-grid,
  .quick-actions,
  .dashboard-analysis-layout,
  .dashboard-bottom-grid,
  .split-layout,
  .content-grid,
  .team-grid {
    grid-template-columns: 1fr 1fr;
  }

  .main {
    padding: 22px;
  }

  .topbar {
    padding: 16px;
  }
}

@media (max-width: 940px) {
  .report-hub-header-panel .panel-heading,
  .report-header-actions,
  .report-assessment-picker,
  .report-meta-strip,
  .report-view-mode-tabs {
    min-width: 0;
    max-width: 100%;
  }

  .report-hub-header-panel .panel-heading > div {
    min-width: 0;
    max-width: 100%;
  }

  .report-hub-header-panel h2 {
    line-height: 1.35;
    white-space: normal;
  }

  .report-hub-header-panel h2 span,
  .report-hub-header-panel p,
  .report-mode-tab span,
  .teacher-assessment-banner p,
  .teacher-assessment-banner strong {
    overflow-wrap: anywhere;
  }

  .report-header-actions {
    width: 100%;
    align-items: stretch !important;
  }

  .report-header-actions .ghost-button,
  .report-header-actions .primary-button {
    width: auto;
    flex: 0 1 auto;
    white-space: normal;
    text-align: center;
  }

  .report-view-mode-tabs {
    flex-direction: column;
    overflow-x: visible;
    -webkit-overflow-scrolling: touch;
    border-bottom: 0 !important;
    gap: 6px !important;
  }

  .report-mode-tab {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
    justify-content: center;
    border: 1px solid #e2e8f0 !important;
    border-radius: 8px;
    margin-bottom: 0 !important;
    white-space: normal;
    text-align: center;
  }

  .teacher-assessment-banner {
    flex-direction: column;
    align-items: stretch !important;
  }

  .teacher-assessment-banner > div:first-child,
  .teacher-assessment-actions {
    min-width: 0;
    max-width: 100%;
  }

  .teacher-assessment-actions {
    width: 100%;
    flex-wrap: wrap;
    flex-shrink: 1 !important;
  }

  .teacher-assessment-actions .primary-button,
  .teacher-assessment-actions .ghost-button {
    flex: 1 1 150px;
    width: auto;
    white-space: normal !important;
  }
}

@media (max-width: 940px) {
  .topbar-actions {
    flex-wrap: wrap;
  }

  .action-field.assessment-field {
    width: 100%;
    flex: 1 1 100%;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .search-box {
    width: 100%;
  }

  .metric-card {
    min-height: 112px;
  }

  .dashboard-hero,
  .dashboard-summary-top,
  .dashboard-workspace-grid,
  .dashboard-analysis-layout,
  .dashboard-bottom-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-metric-strip {
    grid-template-columns: 1fr 1fr;
  }

  .quick-actions {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .main {
    padding: 16px 12px;
  }

  .topbar-header-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .topbar-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .action-field {
    width: 100%;
    display: flex;
    justify-content: space-between;
    min-width: 0;
  }

  .action-field.assessment-field {
    min-width: 0;
  }

  .action-field.live-test-action {
    margin-left: 0 !important;
  }

  .action-field.live-test-action .primary-button {
    width: 100%;
    justify-content: center;
    white-space: normal !important;
  }

  .action-label {
    white-space: normal;
  }

  .select-compact,
  .select-elongated {
    min-width: 0;
  }

  .metric-grid,
  .quick-actions,
  .dashboard-analysis-layout,
  .dashboard-bottom-grid,
  .split-layout,
  .content-grid,
  .field-pair,
  .nav-tabs,
  .sidebar-footer,
  .team-grid {
    grid-template-columns: 1fr;
  }

  .nav-tab {
    justify-content: flex-start;
  }

  .brand {
    padding-bottom: 12px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .user-card {
    align-items: flex-start;
  }

  .metric-card,
  .panel,
  .login-panel {
    box-shadow: 0 10px 24px rgba(20, 33, 43, 0.06);
  }

  .table-wrap,
  .batch-student-preview-table-wrap,
  .roster-table-container {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 680px;
  }

  th,
  td {
    padding: 10px 8px;
  }

  .score-table th:first-child,
  .score-table td:first-child {
    min-width: 168px;
  }

  .toast-stack {
    right: 14px;
    bottom: 14px;
  }
}

@media (max-width: 520px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    background: var(--bg);
  }

  .login-screen {
    padding: 14px;
  }

  .login-panel {
    padding: 20px;
  }

  .login-panel h1,
  .topbar h1 {
    font-size: 1.45rem;
  }

  .topbar,
  .topbar-actions,
  .panel,
  .metric-card,
  .dashboard-summary-panel,
  .student-management-panel,
  .report-hub-header-panel {
    min-width: 0;
    max-width: 100%;
  }

  .topbar-user-badge {
    width: 100%;
    justify-content: flex-start;
    border-radius: 12px;
  }

  .user-info-mini {
    min-width: 0;
  }

  .user-info-mini strong,
  .user-info-mini span,
  .brand strong,
  .brand span,
  .panel-heading h2,
  .panel-heading h3,
  .team-card strong,
  .insight-item strong,
  .student-report strong,
  .bar-row strong {
    overflow-wrap: anywhere;
  }

  .sidebar {
    padding: 12px;
  }

  .nav-tabs {
    gap: 6px;
  }

  .nav-tab,
  .ghost-button,
  .primary-button {
    min-height: 46px;
  }

  .panel {
    padding: 14px;
  }

  .panel-heading {
    gap: 10px;
  }

  .metric-card {
    min-height: 104px;
    padding: 15px;
  }

  .dashboard-hero {
    padding: 16px;
  }

  .dashboard-summary-top {
    gap: 12px;
  }

  .summary-actions-bar {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100%;
  }

  .quick-btn {
    width: 100%;
    min-width: 0;
    justify-content: center;
    white-space: normal;
  }

  .dashboard-metric-strip {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100%;
  }

  .metric-item {
    min-width: 0;
    width: 100%;
  }

  .hero-badges {
    gap: 6px;
  }

  .quick-action {
    grid-template-columns: 40px 1fr;
    min-height: 78px;
  }

  .metric-card strong {
    font-size: 1.72rem;
  }

  .toolbar-row {
    gap: 8px;
  }

  .score-input {
    width: 64px;
  }

  .chip {
    white-space: normal;
    text-align: center;
    overflow-wrap: anywhere;
  }

  .report-header-actions,
  .report-assessment-picker {
    flex-direction: column;
    width: 100%;
    align-items: stretch !important;
  }

  .report-assessment-picker label {
    white-space: normal !important;
  }

  #reportAssessmentSelect,
  .report-header-actions .primary-button,
  .report-header-actions .ghost-button {
    min-width: 0 !important;
    width: 100% !important;
    justify-content: center;
  }

  .report-kpi-grid {
    grid-template-columns: 1fr !important;
  }

  #reportPaneA4Preview .panel {
    padding: 12px !important;
    align-items: stretch !important;
  }

  #reportPaneA4Preview .panel > div:first-child {
    max-width: 100% !important;
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px;
    padding: 12px !important;
  }

  #reportPaneA4Preview .report-a4-paper-wrapper {
    max-width: 100% !important;
    padding: 18px 12px !important;
    overflow-x: auto;
  }

  .team-grid.compact {
    grid-template-columns: 1fr;
  }

  .status-strip {
    gap: 6px;
  }

  .status-pill {
    width: 100%;
    justify-content: center;
  }
}

@media (pointer: coarse) {
  .icon-button {
    width: 42px;
    height: 42px;
  }

  select,
  input,
  textarea {
    min-height: 46px;
  }
}

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